Code example for VideoView

Methods: getCurrentPositiongetDurationpausestart

2
			public void onBufferingUpdate(MediaPlayer mp, int percent) {
				Log.d(this.getClass().getName(), "percent: " + percent);
			} 
		}); 
		 
		int time = videoviewer.getDuration();
		int time_elapsed = videoviewer.getCurrentPosition();
		progressBar.setProgress(time_elapsed);
 
		// update current playback time every 500ms until stop 
		timer = new CountDownTimer(time, 500) {
 
			@Override 
			public void onTick(long millisUntilFinished) {
				timeElapsed.setText(countTime(videoviewer.getCurrentPosition()));
				float a = videoviewer.getCurrentPosition();
				float b = videoviewer.getDuration();
				progressBar.setProgress((int) (a / b * 100));
			} 
 
			@Override 
			public void onFinish() { 
				stopMedia(); 
			} 
		}; 
 
 
		timeEnd.setText(countTime(time));
		timeElapsed.setText(countTime(time_elapsed));
		playMedia(true); 
	} 
 
	/** 
     * Convert time from milliseconds into minutes and seconds, proper to media player 
     *  
     * @param miliseconds	media content time in milliseconds 
     * @return	time in format minutes:seconds 
     */ 
    public String countTime(int miliseconds) {
    	String timeInMinutes = new String();
    	int minutes = miliseconds / 60000;
    	int seconds = (miliseconds % 60000)/1000;
    	timeInMinutes = minutes + ":" + (seconds<10?"0" + seconds:seconds);
		return timeInMinutes;
    } 
     
    /** 
     * Start or Pause playback of media content 
     *  
     * @param v	View the touch event has been dispatched to 
     */ 
	public void playMedia(boolean isplay) {
		 
			if (isplay) {
				videoviewer.start();
				timer.start();
			} else { 
				videoviewer.pause();
				timer.cancel();
			} 
		 
    }