Android VideoView - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android VideoView class.

This code example shows how to use the following methods:setVideoURI, start
        return mCustomView;
    } 
 
    @Override 
    public void navigate(String url) {
        mVideoView.setVideoURI(Uri.parse(url));
        mVideoView.start();
    } 
 
    @Override 
    public void stop() { 
        mVideoView.stopPlayback();
    } 
 
    @Override 
    public void destroyView() { 
        mVideoView.stopPlayback();
        mCustomViewCallback.onCustomViewHidden();
    } 
 
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:isPlaying, start
	} 
	 
	//----------------------------------------------------------------// 
	public void startPlayback () { 
		 
		if ( mVideoView.isPlaying ()) {
 
			mVideoView.resume ();
		} else { 
 
			mVideoView.start ();
		} 
	} 
	 
	//----------------------------------------------------------------// 
	public void pausePlayback () { 
		 
		mVideoView.pause ();
	} 
 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:canSeekForward, getDuration, isPlaying, seekTo, start
              
       // Don't start until ready to play.  The arg of seekTo(arg) is the start point in 
       // milliseconds from the beginning. In this example we start playing 1/5 of 
       // the way through the video if the player can do forward seeks on the video. 
        
       if(videoPlayer.canSeekForward()) videoPlayer.seekTo(videoPlayer.getDuration()/5);
       videoPlayer.start();
       Log.i("IS PLAYING", Boolean.toString(videoPlayer.isPlaying()));
    } 
     
    /** This callback will be invoked when the file is finished playing */ 
    @Override 
    public void onCompletion(MediaPlayer  mp) {
       // Statements to be executed when the video finishes. 
       this.finish();	
    } 
     
    /**  Use screen touches to toggle the video between playing and paused. */ 
    @Override 
    public boolean onTouchEvent (MotionEvent ev){
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setMediaController, setOnCompletionListener, setVideoURI, start
	Uri location;
	private EpicClickListener listener;
 
	public EpicNativeVideoWidget(String stringLocation, EpicClickListener l) {
		this.listener = l;
		t = new VideoView(EpicAndroidActivity.getCurrentAndroidActivity());
		t.setOnCompletionListener(this);
		this.location = Uri.parse(stringLocation);
		t.setVideoURI(this.location);
        t.setMediaController(new MediaController(EpicAndroidActivity.getCurrentAndroidActivity()));
//      t.requestFocus(); 
        t.start();
	} 
 
	View getAndroidView() {
		return t;
	} 
 
	public void onCompletion(MediaPlayer arg0) {
		this.listener.onClick();
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setOnCompletionListener, setVideoURI
        } 
    } 
    public VideoView createVideoView(String resourcePath) {
        if(video==null){
            Log.i(TAG, "Creating video view");
            video = new VideoView(GameActivity.getContext());
            video.setOnCompletionListener(this);
            Log.i(TAG, "Setting...");
			try{ 
				GameActivity.pushView(video);
			}catch(Exception e){
				Log.e(TAG,"Ruh roh");
			} 
            Log.i(TAG, "Video view set as current");
        }else{ 
            video.stopPlayback();
        } 
        Log.i(TAG, "Setting video uri");
        video.setVideoURI(Utils.buildResourceUri(GameActivity.getContext(), GameActivity.getResourceID(resourcePath)));
        return video;

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setMediaController, setOnCompletionListener, setOnErrorListener, setOnPreparedListener
  public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.video_surface, container, false);
    this.progress = view.findViewById(R.id.progress);
    final VideoView videoView = (VideoView)view.findViewById(R.id.video);
    this.videoView = videoView;
    videoView.setOnPreparedListener(this);
    videoView.setOnErrorListener(this);
    videoView.setOnCompletionListener(this);
    this.controller = new MediaController(getOwnerActivity());
    videoView.setMediaController(controller);
    return view;
  } 
 
  @Override 
  public void onActivityCreated(final Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    openVideo(); 
  } 
 
  @Override 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getDuration, start
            public void onPrepared(MediaPlayer mp) {
                // 3,4秒でMediaControllerが消えちゃうので 
                // 常に表示させておきたいんだけど 
                // showメソッドが期待通りに動作してくれない 
                // durationは正しく取得できてる。 
                int duration = mVideoView.getDuration();
                mMediaController.show(duration);
                // リファレンスを信じて0にしてもダメ 
//                mMediaController.show(0); 
 
                // まぁ気にせず再生スタート! 
                mVideoView.start();
            } 
        }); 
    } 
 
    public void onPickAndVideoViewButton(View view) {
        startVideoPicker(1); 
    } 
 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setVideoURI, start
 
			@Override 
			public void run() { 
				pbar.setVisibility(View.GONE);
				if (video != null) {
					videoView.setVideoURI(Uri.parse(new File(video
							.getVideoFilePath()).toString()));
					videoView.start();
					imageViewThumb.setImageURI(Uri.parse(new File(video
							.getThumbnailPath()).toString()));
					imageViewThumbSmall.setImageURI(Uri.parse(new File(video
							.getThumbnailSmallPath()).toString()));
				} 
			} 
		}); 
	} 
 
	@Override 
	public void onError(final String reason) {
		runOnUiThread(new Runnable() {
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:isPlaying
 
    Handler mHandler = new Handler();
 
    Runnable mPlayingChecker = new Runnable() {
        public void run() { 
            if (mVideoView.isPlaying()) { 
                mProgressView.setVisibility(View.GONE); 
            } else { 
                mHandler.postDelayed(mPlayingChecker, 250); 
            } 
        } 
    }; 
 
    public MovieViewControl(View rootView, Context context, Uri videoUri) {
        mContentResolver = context.getContentResolver();
        mVideoView = (VideoView) rootView.findViewById(R.id.surface_view);
        mProgressView = rootView.findViewById(R.id.progress_indicator);
 
        mUri = videoUri;
 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getCurrentPosition, isPlaying, stopPlayback

Related Android VideoView Questions & Answers:

Other Android VideoView Examples

12:	
13:		private ImageView imgPreview;
14:		private VideoView videoPreview;
15:		private Button btnCapturePicture, btnRecordVideo;
16:	
-
21:	
22:			imgPreview = (ImageView) findViewById(R.id.imgPreview);
23:			videoPreview = (VideoView) findViewById(R.id.videoPreview);
24:			btnCapturePicture = (Button) findViewById(R.id.btnCapturePicture);
25:			btnRecordVideo = (Button) findViewById(R.id.btnRecordVideo);

Read More

35:	
36:		private ImageView imgPreview;
37:		private VideoView videoPreview;
38:		private Button btnCapturePicture, btnRecordVideo;
39:	
-
44:	
45:			imgPreview = (ImageView) findViewById(R.id.imgPreview);
46:			videoPreview = (VideoView) findViewById(R.id.videoPreview);
47:			btnCapturePicture = (Button) findViewById(R.id.btnCapturePicture);
48:			btnRecordVideo = (Button) findViewById(R.id.btnRecordVideo);

Read More