I have a problem that I want to get total length of video which is running in Video View for this I am using getDuration Method of video view but it always returns -1 when I am comparing it with currentPosition. Actually I want that if video's currentposition is equals to the total length of the video then it should start from the 0th position means starting. Mean I want to say that I want to compare Video current position with the total length of the video, how can I do that?
Thanks in advance.
Code:
videoPosition=VideoPositionFinding(IDValue,video.getDuration());
video.seekTo(videoPosition);
if(video.getCurrentPosition()==video.getDuration()){
videoPosition=0;
}
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
System.out.println("The Video Duration: "+video.getCurrentPosition());
video.start();
To get total length of video use code:
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
long duration = videoView.getDuration();
}
});
To get length of video use the below code
myVideoView.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
// TODO Auto-generated method stub
int duration=mp.getDuration()/1000;
int hours = duration / 3600;
int minutes = (duration / 60) - (hours * 60);
int seconds = duration - (hours * 3600) - (minutes * 60) ;
String formatted = String.format("%d:%02d:%02d", hours, minutes, seconds);
Toast.makeText(getApplicationContext(), "duration is " + formatted , Toast.LENGTH_LONG).show();
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With