如何在Android的视频视图中获取视频的总长度 [英] how to get total length of video in video view in android
问题描述
我有一个问题,我要为此在视频视图中运行的视频的总长度,我正在使用视频视图的getDuration方法,但是在将它与currentPosition进行比较时,它始终返回-1.实际上,我希望如果视频的当前位置等于视频的总长度,那么它应该从第0个位置开始,即开始.意思是说我想比较视频的当前位置和视频的总长度,我该怎么做?
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?
提前谢谢.
代码:
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();
}
});
这篇关于如何在Android的视频视图中获取视频的总长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!