类android.widget.VideoView源码实例Demo

下面列出了怎么用android.widget.VideoView的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: PLDroidShortVideo   文件: VideoTrimActivity.java
private void init(String videoPath) {
    setContentView(R.layout.activity_trim);
    TextView duration = (TextView) findViewById(R.id.duration);
    mPreview = (VideoView) findViewById(R.id.preview);

    mShortVideoTrimmer = new PLShortVideoTrimmer(this, videoPath, Config.TRIM_FILE_PATH);
    mMediaFile = new PLMediaFile(videoPath);

    mSelectedEndMs = mDurationMs = mMediaFile.getDurationMs();
    duration.setText("时长: " + formatTime(mDurationMs));
    Log.i(TAG, "video duration: " + mDurationMs);

    mVideoFrameCount = mMediaFile.getVideoFrameCount(false);
    Log.i(TAG, "video frame count: " + mVideoFrameCount);

    mPreview.setVideoPath(videoPath);
    mPreview.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mediaPlayer) {
            play();
        }
    });

    initVideoFrameList();
}
 
源代码2 项目: PLDroidShortVideo   文件: VideoDivideActivity.java
private void initView() {
    setContentView(R.layout.activity_video_divide);

    mPreview = (VideoView) findViewById(R.id.preview);
    mPlaybackButton = (ImageButton) findViewById(R.id.pause_playback);
    mFrameListParent = (ViewGroup) findViewById(R.id.recycler_parent);
    mFrameList = (RecyclerView) findViewById(R.id.recycler_frame_list);
    mScrollViewParent = (FrameLayout) findViewById(R.id.scroll_view_parent);
    mScrollView = (ObservableHorizontalScrollView) findViewById(R.id.scroll_view);

    ImageView middleLineImage = (ImageView) findViewById(R.id.middle_line_image);
    ViewGroup topGroup = (ViewGroup) findViewById(R.id.top_group);

    WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    mFrameWidth = mFrameHeight = wm.getDefaultDisplay().getWidth() / 6;
    middleLineImage.getLayoutParams().height = mFrameHeight;

    mScrollView.setOnScrollListener(new OnViewScrollListener());
    topGroup.setOnTouchListener(new OnTopViewTouchListener());
}
 
源代码3 项目: MediaLoader   文件: VideoPagerFragment.java
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_media, container, false);
    mVideoView = (VideoView) rootView.findViewById(R.id.videoView);
    mVideoViewSeekBar = (VideoViewSeekBar) rootView.findViewById(R.id.mediaSeekBar);
    mVideoViewSeekBar.setVideoView(mVideoView);
    mUrl = getArguments().getString(BUNDLE_KEY_URL);

    mMediaLoader = MediaLoader.getInstance(getContext());
    mMediaLoader.addDownloadListener(mUrl, this);
    boolean isCached = mMediaLoader.isCached(mUrl);
    if (isCached) {
        mVideoViewSeekBar.setSecondaryProgress(mVideoViewSeekBar.getMax());
    }
    mVideoView.setVideoPath(mMediaLoader.getProxyUrl(mUrl));
    return rootView;
}
 
源代码4 项目: MediaLoader   文件: VideoLazyLoadFragment.java
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_media, container, false);
    mVideoView = (VideoView) rootView.findViewById(R.id.videoView);
    mVideoViewSeekBar = (VideoViewSeekBar) rootView.findViewById(R.id.mediaSeekBar);
    mVideoViewSeekBar.setVideoView(mVideoView);
    mUrl = getArguments().getString(BUNDLE_KEY_URL);

    mMediaLoader = MediaLoader.getInstance(getContext());
    mMediaLoader.addDownloadListener(mUrl, this);
    boolean isCached = mMediaLoader.isCached(mUrl);
    if (isCached) {
        mVideoViewSeekBar.setSecondaryProgress(mVideoViewSeekBar.getMax());
    }
    return rootView;
}
 
源代码5 项目: MediaLoader   文件: MediaFragment.java
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_media, container, false);
    mVideoView = (VideoView) rootView.findViewById(R.id.videoView);
    mVideoViewSeekBar = (VideoViewSeekBar) rootView.findViewById(R.id.mediaSeekBar);
    mVideoViewSeekBar.setVideoView(mVideoView);
    mUrl = getArguments().getString(BUNDLE_KEY_URL);

    mMediaLoader = MediaLoader.getInstance(getContext());
    mMediaLoader.addDownloadListener(mUrl, this);
    boolean isCached = mMediaLoader.isCached(mUrl);
    if (isCached) {
        mVideoViewSeekBar.setSecondaryProgress(mVideoViewSeekBar.getMax());
    }
    mVideoView.setVideoPath(mMediaLoader.getProxyUrl(mUrl));
    mVideoViewSeekBar.start();
    return rootView;
}
 
源代码6 项目: CastVideos-android   文件: LocalPlayerActivity.java
private void loadViews() {
    mVideoView = (VideoView) findViewById(R.id.videoView1);
    mTitleView = (TextView) findViewById(R.id.titleTextView);
    mDescriptionView = (TextView) findViewById(R.id.descriptionTextView);
    mDescriptionView.setMovementMethod(new ScrollingMovementMethod());
    mAuthorView = (TextView) findViewById(R.id.authorTextView);
    mStartText = (TextView) findViewById(R.id.startText);
    mStartText.setText(Utils.formatMillis(0));
    mEndText = (TextView) findViewById(R.id.endText);
    mSeekbar = (SeekBar) findViewById(R.id.seekBar1);
    mPlayPause = (ImageView) findViewById(R.id.playPauseImageView);
    mLoading = (ProgressBar) findViewById(R.id.progressBar1);
    mControllers = findViewById(R.id.controllers);
    mContainer = findViewById(R.id.container);
    mCoverArt = (NetworkImageView) findViewById(R.id.coverArtView);
    ViewCompat.setTransitionName(mCoverArt, getString(R.string.transition_image));
    mPlayCircle = (ImageButton) findViewById(R.id.play_circle);
    mPlayCircle.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            togglePlayback();
        }
    });
}
 
源代码7 项目: commcare-android   文件: FormEntryActivity.java
private void restoreInlineVideoState() {
    if (indexOfWidgetWithVideoPlaying != -1) {
        QuestionWidget widgetWithVideoToResume = uiController.questionsView.getWidgets().get(indexOfWidgetWithVideoPlaying);
        VideoView inlineVideo = widgetWithVideoToResume.findViewById(MediaLayout.INLINE_VIDEO_PANE_ID);
        if (inlineVideo != null) {
            inlineVideo.seekTo(positionOfVideoProgress);
            inlineVideo.start();
        } else {
            Logger.log(LogTypes.SOFT_ASSERT,
                    "No inline video was found at the question widget index for which a " +
                            "video had been playing before the activity was paused");
        }

        // Reset values now that we have restored
        indexOfWidgetWithVideoPlaying = -1;
        positionOfVideoProgress = -1;
    }
}
 
源代码8 项目: Cirrus_depricated   文件: PreviewMediaFragment.java
/**
 * {@inheritDoc}
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    Log_OC.v(TAG, "onCreateView");

    mView = inflater.inflate(R.layout.file_preview, container, false);

    mImagePreview = (ImageView) mView.findViewById(R.id.image_preview);
    mVideoPreview = (VideoView) mView.findViewById(R.id.video_preview);
    mVideoPreview.setOnTouchListener(this);

    mMediaController = (MediaControlView) mView.findViewById(R.id.media_controller);

    return mView;
}
 
源代码9 项目: cast-videos-android   文件: LocalPlayerActivity.java
private void loadViews() {
    mVideoView = (VideoView) findViewById(R.id.videoView1);
    mTitleView = (TextView) findViewById(R.id.textView1);
    mDescriptionView = (TextView) findViewById(R.id.textView2);
    mDescriptionView.setMovementMethod(new ScrollingMovementMethod());
    mAuthorView = (TextView) findViewById(R.id.textView3);
    mStartText = (TextView) findViewById(R.id.startText);
    mStartText.setText(Utils.formatMillis(0));
    mEndText = (TextView) findViewById(R.id.endText);
    mSeekbar = (SeekBar) findViewById(R.id.seekBar1);
    mPlayPause = (ImageView) findViewById(R.id.imageView2);
    mLoading = (ProgressBar) findViewById(R.id.progressBar1);
    mControllers = findViewById(R.id.controllers);
    mContainer = findViewById(R.id.container);
    mCoverArt = (ImageView) findViewById(R.id.coverArtView);
    ViewCompat.setTransitionName(mCoverArt, getString(R.string.transition_image));
    mPlayCircle = (ImageButton) findViewById(R.id.play_circle);
    mPlayCircle.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            togglePlayback();
        }
    });
}
 
源代码10 项目: Small   文件: VideoActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_video);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    VideoView videoView = (VideoView) findViewById(R.id.video_view);
    final String uri = "android.resource://" + getPackageName() + "/" + R.raw.fix_429;
    videoView.setVideoURI(Uri.parse(uri));
    // Loop
    videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        @Override
        public void onPrepared(MediaPlayer mp) {
            mp.setLooping(true);
        }
    });
    // Play
    videoView.start();
}
 
源代码11 项目: ScrollGalleryView   文件: VideoPlayerActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    String url = getIntent().getExtras().getString(Constants.URL);
    setContentView(R.layout.video_fragment);
    final VideoView videoView = (VideoView) findViewById(R.id.videoView);
    videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        @Override
        public void onPrepared(MediaPlayer mp) {
            View progress = findViewById(R.id.videoProgress);
            progress.setVisibility(View.GONE);

            videoView.requestFocus();
            MediaController vidControl = new MediaController(VideoPlayerActivity.this);
            vidControl.setAnchorView(videoView);
            videoView.setMediaController(vidControl);
            videoView.start();
        }
    });
    videoView.setVideoURI(Uri.parse(url));
}
 
源代码12 项目: codeexamples-android   文件: VideoViewDemo.java
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.videoview);
    mVideoView = (VideoView) findViewById(R.id.surface_view);

    if (path == "") {
        // Tell the user to provide a media file URL/path.
        Toast.makeText(
                VideoViewDemo.this,
                "Please edit VideoViewDemo Activity, and set path"
                        + " variable to your media file URL/path",
                Toast.LENGTH_LONG).show();

    } else {

        /*
         * Alternatively,for streaming media you can use
         * mVideoView.setVideoURI(Uri.parse(URLstring));
         */
        mVideoView.setVideoPath(path);
        mVideoView.setMediaController(new MediaController(this));
        mVideoView.requestFocus();

    }
}
 
源代码13 项目: tv-samples   文件: Utils.java
/**
 * Example for handling resizing content for overscan.  Typically you won't need to resize when
 * using the Leanback support library.
 */
public void overScan(Activity activity, VideoView videoView) {
    DisplayMetrics metrics = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int w = (int) (metrics.widthPixels * MediaDimensions.MEDIA_WIDTH);
    int h = (int) (metrics.heightPixels * MediaDimensions.MEDIA_HEIGHT);
    int marginLeft = (int) (metrics.widthPixels * MediaDimensions.MEDIA_LEFT_MARGIN);
    int marginTop = (int) (metrics.heightPixels * MediaDimensions.MEDIA_TOP_MARGIN);
    int marginRight = (int) (metrics.widthPixels * MediaDimensions.MEDIA_RIGHT_MARGIN);
    int marginBottom = (int) (metrics.heightPixels * MediaDimensions.MEDIA_BOTTOM_MARGIN);
    FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(w, h);
    lp.setMargins(marginLeft, marginTop, marginRight, marginBottom);
    videoView.setLayoutParams(lp);
}
 
源代码14 项目: AndroidDemoProjects   文件: PlayerActivity.java
private void initViews() {
    mVideoView = (VideoView) findViewById(R.id.videoView);
    mStartText = (TextView) findViewById(R.id.startText);
    mEndText = (TextView) findViewById(R.id.endText);
    mSeekbar = (SeekBar) findViewById(R.id.seekBar);
    mPlayPause = (ImageView) findViewById(R.id.playpause);
    mLoading = (ProgressBar) findViewById(R.id.progressBar);
    mControllers = findViewById(R.id.controllers);

    mVideoView.setOnClickListener( new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if ( mControllers.getVisibility() != View.VISIBLE  ) {
                mControllers.setVisibility( View.VISIBLE );
            }

            if ( mPlaybackState == PlaybackState.PAUSED ) {
                mPlaybackState = PlaybackState.PLAYING;
                updatePlayButton( mPlaybackState );
                mVideoView.start();
                startControllersTimer();
            } else {
                mVideoView.pause();
                mPlaybackState = PlaybackState.PAUSED;
                updatePlayButton( PlaybackState.PAUSED );
                stopControllersTimer();
            }
        }
    });
}
 
源代码15 项目: androidtv-Leanback   文件: Utils.java
/**
 * Example for handling resizing content for overscan.  Typically you won't need to resize when
 * using the Leanback support library.
 */
public void overScan(Activity activity, VideoView videoView) {
    DisplayMetrics metrics = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int w = (int) (metrics.widthPixels * MediaDimensions.MEDIA_WIDTH);
    int h = (int) (metrics.heightPixels * MediaDimensions.MEDIA_HEIGHT);
    int marginLeft = (int) (metrics.widthPixels * MediaDimensions.MEDIA_LEFT_MARGIN);
    int marginTop = (int) (metrics.heightPixels * MediaDimensions.MEDIA_TOP_MARGIN);
    int marginRight = (int) (metrics.widthPixels * MediaDimensions.MEDIA_RIGHT_MARGIN);
    int marginBottom = (int) (metrics.heightPixels * MediaDimensions.MEDIA_BOTTOM_MARGIN);
    FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(w, h);
    lp.setMargins(marginLeft, marginTop, marginRight, marginBottom);
    videoView.setLayoutParams(lp);
}
 
源代码16 项目: FoodOrdering   文件: Activity_VideoSurveillance.java
private void initView() {
    pg=new ProgressDialog(Activity_VideoSurveillance.this);
    pg.setMessage("缓冲中...");
    pg.show();

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle("");
    TextView toolbarText = (TextView) findViewById(R.id.toolbar_text);
    toolbarText.setText("视频监控");
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    if (!Util.checkNetwork(this)) {
        return;
    }
    videoViewVideo = (VideoView) findViewById(R.id.videoViewVideo);

    try {
        //设置视频控制器
        MediaController mediacontroller = new MediaController(Activity_VideoSurveillance.this);
        mediacontroller.setAnchorView(videoViewVideo);
        videoViewVideo.setMediaController(mediacontroller);
        //视频来源
        videoViewVideo.setVideoURI(Uri.parse("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"));
    } catch (Exception e) {
        e.printStackTrace();
        pg.dismiss();
    }
    videoViewVideo.requestFocus();
    videoViewVideo.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        // Close the progress bar and play the video
        public void onPrepared(MediaPlayer mp) {
            pg.dismiss();
            //开始播放视频
            videoViewVideo.start();
        }
    });
}
 
@Override
protected void onActivityResult(int requestCode,
                                int resultCode, Intent data) {
  if (requestCode == RECORD_VIDEO) {
    VideoView videoView = findViewById(R.id.videoView);
    videoView.setVideoURI(data.getData());
    videoView.start();
  }
}
 
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	this.requestWindowFeature(Window.FEATURE_NO_TITLE);
	this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

	Bundle b = getIntent().getExtras();
	mVideoUrl = b.getString("mediaUrl");
	mShouldAutoClose = b.getBoolean("shouldAutoClose", true);
	mControls = b.getBoolean("controls", true);

	RelativeLayout relLayout = new RelativeLayout(this);
	relLayout.setBackgroundColor(Color.BLACK);
	RelativeLayout.LayoutParams relLayoutParam = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
	relLayoutParam.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
	mVideoView = new VideoView(this);
	mVideoView.setLayoutParams(relLayoutParam);
	relLayout.addView(mVideoView);

	// Create progress throbber
	mProgressBar = new ProgressBar(this);
	mProgressBar.setIndeterminate(true);
	// Center the progress bar
	RelativeLayout.LayoutParams pblp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
	pblp.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
	mProgressBar.setLayoutParams(pblp);
	// Add progress throbber to view
	relLayout.addView(mProgressBar);
	mProgressBar.bringToFront();

	setOrientation(b.getString("orientation"));

	setContentView(relLayout, relLayoutParam);

	play();
}
 
源代码19 项目: browser   文件: BrowserActivity.java
@Override
public void onShowCustomView(View view, int requestedOrientation, CustomViewCallback callback) {
	if (view == null) {
		return;
	}
	if (mCustomView != null && callback != null) {
		callback.onCustomViewHidden();
		return;
	}
	try {
		view.setKeepScreenOn(true);
	} catch (SecurityException e) {
		Log.e(Constants.TAG, "WebView is not allowed to keep the screen on");
	}
	mOriginalOrientation = getRequestedOrientation();
	FrameLayout decor = (FrameLayout) getWindow().getDecorView();
	mFullscreenContainer = new FullscreenHolder(this);
	mCustomView = view;
	mFullscreenContainer.addView(mCustomView, COVER_SCREEN_PARAMS);
	decor.addView(mFullscreenContainer, COVER_SCREEN_PARAMS);
	setFullscreen(true);
	getCurrentWebView().setVisibility(View.GONE);
	if (view instanceof FrameLayout) {
		if (((FrameLayout) view).getFocusedChild() instanceof VideoView) {
			mVideoView = (VideoView) ((FrameLayout) view).getFocusedChild();
			mVideoView.setOnErrorListener(new VideoCompletionListener());
			mVideoView.setOnCompletionListener(new VideoCompletionListener());
		}
	}
	mCustomViewCallback = callback;
}
 
源代码20 项目: AnotherRSS   文件: VideocastActivity.java
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_videoweb);
    VideoView videoView = (VideoView) findViewById(R.id.videoView);
    WebView webView = (WebView) findViewById(R.id.webView);
    progressBar = (ProgressBar) findViewById(R.id.progressBar);
    Intent intent = getIntent();
    Uri uri = intent.getData();
    if (uri != null) {
        String url = uri.toString();
        if (url.endsWith(".mp4")) {
            webView.setVisibility(View.GONE);
            progressBar.setVisibility(View.GONE);
            videoView.setVisibility(View.VISIBLE);
            videoView.setMediaController(AnotherRSS.mediaController);
            videoView.setVideoURI(uri);
            videoView.requestFocus();
            videoView.start();
        } else {
            webView.setVisibility(View.VISIBLE);
            progressBar.setVisibility(View.VISIBLE);
            videoView.setVisibility(View.GONE);
            webView.setWebViewClient(new MyWebClient());
            webView.getSettings().setJavaScriptEnabled(true);
            webView.getSettings().setLoadWithOverviewMode(true);
            webView.getSettings().setUseWideViewPort(true);
            webView.loadUrl(url);
        }
    }
}
 
源代码21 项目: VideoRecord   文件: VideoPlayActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_video_play);
    libPlayVideo_tv_title = (TextView) findViewById(R.id.libPlayVideo_tv_title);
    libPlayVideo_tv_title.setText("视频播放");
    videoView = (VideoView) findViewById(R.id.libPlayVideo_videoView);
    videoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
        @Override
        public boolean onError(MediaPlayer mp, int what, int extra) {
            if (isFirst) {
                isFirst = false;
                Toast.makeText(VideoPlayActivity.this, "播放该视频异常", Toast.LENGTH_SHORT).show();
            }
            return true;
        }
    });

    String mVideoPath = getIntent().getStringExtra(VedioRecordActivity.kVideoSavePath);
    File file = new File(mVideoPath);
    if (file.exists()) {
        videoView.setVideoPath(file.getAbsolutePath());
        videoView.start();
        setLoop(file.getAbsolutePath());
    } else {
        Log.e("tag","not found video " + mVideoPath);
    }
}
 
源代码22 项目: BBSSDK-for-Android   文件: PageVideoViewer.java
protected View initViewerContentView(Context context) {
	RelativeLayout rl = new RelativeLayout(context);
	videoView = new VideoView(context);
	RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
	rlp.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
	rl.addView(videoView, rlp);
	return rl;
}
 
源代码23 项目: Insta-Downloader   文件: InstaAdapter.java
private InstaVH(View itemView) {
    super(itemView);

    hImage = (ImageView) itemView.findViewById(R.id.image);
    hRepost = (ImageView) itemView.findViewById(R.id.repost);
    hDownload = (ImageView) itemView.findViewById(R.id.download);
    hVideoImg = (ImageView) itemView.findViewById(R.id.imagevideo);
    hVideo = (VideoView) itemView.findViewById(R.id.pvideo);
}
 
源代码24 项目: appinventor-extensions   文件: MediaUtil.java
/**
 * Loads the video specified by mediaPath into the given VideoView.
 *
 * Note that if the mediaPath is an asset or an URL, the video must be copied
 * to a temp file and then loaded from there. This could have performance
 * implications.
 *
 * @param videoView the VideoView
 * @param form the Form
 * @param mediaPath the path to the media
 */
public static void loadVideoView(VideoView videoView, Form form, String mediaPath)
    throws IOException {
  MediaSource mediaSource = determineMediaSource(form, mediaPath);
  switch (mediaSource) {
    case ASSET:
    case URL:
      File tempFile = cacheMediaTempFile(form, mediaPath, mediaSource);
      videoView.setVideoPath(tempFile.getAbsolutePath());
      return;

    case REPL_ASSET:
      form.assertPermission(Manifest.permission.READ_EXTERNAL_STORAGE);
      videoView.setVideoPath(replAssetPath(mediaPath));
      return;

    case SDCARD:
      form.assertPermission(Manifest.permission.READ_EXTERNAL_STORAGE);
      videoView.setVideoPath(mediaPath);
      return;

    case FILE_URL:
      if (isExternalFileUrl(mediaPath)) {
        form.assertPermission(Manifest.permission.READ_EXTERNAL_STORAGE);
      }
      videoView.setVideoPath(fileUrlToFilePath(mediaPath));
      return;

    case CONTENT_URI:
      videoView.setVideoURI(Uri.parse(mediaPath));
      return;

    case CONTACT_URI:
      throw new IOException("Unable to load video for contact " + mediaPath + ".");
  }
  throw new IOException("Unable to load video " + mediaPath + ".");
}
 
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.main);

	// Get a reference to the VideoView
	
	mVideoView = (VideoView) findViewById(R.id.videoViewer);

	// Add a Media controller to allow forward/reverse/pause/resume 
	
	final MediaController mMediaController = new MediaController(
			AudioVideoVideoPlayActivity.this, true);
	
	mMediaController.setEnabled(false);

	mVideoView.setMediaController(mMediaController);
	
	mVideoView
			.setVideoURI(Uri
					.parse("android.resource://course.examples.AudioVideo.VideoPlay/raw/moon"));
	
	// Add an OnPreparedListener to enable the MediaController once the video is ready
	mVideoView.setOnPreparedListener(new OnPreparedListener() {

		@Override
		public void onPrepared(MediaPlayer mp) {
			mMediaController.setEnabled(true);
		}
	});
}
 
源代码26 项目: Cirrus_depricated   文件: PreviewVideoActivity.java
/**
 *  Called when the activity is first created.
 *
 *  Searches for an {@link OCFile} and ownCloud {@link Account} holding it in the starting {@link Intent}.
 *
 *  The {@link Account} is unnecessary if the file is downloaded; else, the {@link Account} is used to
 *  try to stream the remote file - TODO get the streaming works
 *
 *  {@inheritDoc}
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log_OC.v(TAG, "onCreate");

    setContentView(R.layout.video_layout);

    if (savedInstanceState == null) {
        Bundle extras = getIntent().getExtras();
        mSavedPlaybackPosition = extras.getInt(EXTRA_START_POSITION);
        mAutoplay = extras.getBoolean(EXTRA_AUTOPLAY);

    } else {
        mSavedPlaybackPosition = savedInstanceState.getInt(EXTRA_START_POSITION);
        mAutoplay = savedInstanceState.getBoolean(EXTRA_AUTOPLAY);
    }

    mVideoPlayer = (VideoView) findViewById(R.id.videoPlayer);

    // set listeners to get more contol on the playback
    mVideoPlayer.setOnPreparedListener(this);
    mVideoPlayer.setOnCompletionListener(this);
    mVideoPlayer.setOnErrorListener(this);

    // keep the screen on while the playback is performed (prevents screen off by battery save)
    mVideoPlayer.setKeepScreenOn(true);
}
 
源代码27 项目: ml-authentication   文件: VideoActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.i(getClass().getName(), "onCreate");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_video);

    getWindow().setStatusBarColor(Color.parseColor("#852196"));

    LiteracyApplication literacyApplication = (LiteracyApplication) getApplicationContext();
    videoDao = literacyApplication.getDaoSession().getVideoDao();

    videoView = (VideoView) findViewById(R.id.videoView);
}
 
源代码28 项目: deltachat-android   文件: VideoPlayer.java
private void initializeVideoViewControls(@NonNull VideoView videoView) {
  MediaController mediaController = new MediaController(getContext());
  mediaController.setAnchorView(videoView);
  mediaController.setMediaPlayer(videoView);

  videoView.setMediaController(mediaController);
}
 
private void initViews() {
	btn_switch = (Button) findViewById(R.id.switch_btn);
	btn_switch.setOnClickListener(this);
	btn_switch.setVisibility(View.VISIBLE);
	mVideoView = (VideoView) findViewById(R.id.mVideoView);
	btnStart = (ImageView) findViewById(R.id.recorder_start);
	btnStop = (ImageView) findViewById(R.id.recorder_stop);
	btnStart.setOnClickListener(this);
	btnStop.setOnClickListener(this);
	mSurfaceHolder = mVideoView.getHolder();
	mSurfaceHolder.addCallback(this);
	mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
	chronometer = (Chronometer) findViewById(R.id.chronometer);
}
 
源代码30 项目: BuildingForAndroidTV   文件: PlayerActivity.java
private void loadViews() {
    mVideoView = (VideoView) findViewById(R.id.videoView);
    mStartText = (TextView) findViewById(R.id.startText);
    mEndText = (TextView) findViewById(R.id.endText);
    mSeekbar = (SeekBar) findViewById(R.id.seekBar);
    mPlayPause = (ImageView) findViewById(R.id.playpause);
    mLoading = (ProgressBar) findViewById(R.id.progressBar);
    mControllers = findViewById(R.id.controllers);
    mContainer = findViewById(R.id.container);

    mVideoView.setOnClickListener(mPlayPauseHandler);
}
 
 类所在包
 同包方法