How To Get Total Length Of Video In Video View In Android
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 com
Solution 1:
To get total length of video use code:
videoView.setOnPreparedListener(newMediaPlayer.OnPreparedListener() {
@OverridepublicvoidonPrepared(MediaPlayer mp) {
longduration= videoView.getDuration();
}
});
Solution 2:
To get length of video use the below code
myVideoView.setOnPreparedListener(newOnPreparedListener() {
@OverridepublicvoidonPrepared(MediaPlayer mp) {
// TODO Auto-generated method stubint duration=mp.getDuration()/1000;
inthours= duration / 3600;
intminutes= (duration / 60) - (hours * 60);
intseconds= duration - (hours * 3600) - (minutes * 60) ;
Stringformatted= String.format("%d:%02d:%02d", hours, minutes, seconds);
Toast.makeText(getApplicationContext(), "duration is " + formatted , Toast.LENGTH_LONG).show();
}
});
Solution 3:
You can use below code :
int duration = MediaPlayer.create(context, Uri.fromFile(newFile(video_path))).getDuration();
Solution 4:
I think there is not a direct way to implement this, but by these function you can done this. you should try .
public int getBufferPercentage ()
public int getDuration ()
http://developer.android.com/reference/android/widget/VideoView.html
Solution 5:
Why are you using LOCATION_SERVICE to get the video position? The LOCATION_SERVICE is meant for pinpointing device's location. Refer to this link.
Post a Comment for "How To Get Total Length Of Video In Video View In Android"