How to get the total length of video in video in android

I have a problem with the fact that I want to get the total length of a video that works in Video View for this. I use the getDuration view method to view the video, but it always returns -1 when I compare it to currentPosition. In fact, I want that if the current video image is equal to the total length of the video, it should start from 0 position means start. I want to say that I want to compare the current position of the video with the total length of the video, how can I do this?

Thanks in advance.

The 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(); 
+6
source share
5 answers

To get the total length of the video usage code:

 videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { long duration = videoView.getDuration(); } }); 
+13
source

To get the length of the video, use the code below

 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(); } }); 
+6
source

You can use the code below:

 int duration = MediaPlayer.create(context, Uri.fromFile(new File(video_path))).getDuration(); 
0
source

I think there is no direct way to implement this, but with this function you can do it. You must try.

public int getBufferPercentage ()

public int getDuration ()

http://developer.android.com/reference/android/widget/VideoView.html

-1
source

Why are you using LOCATION_SERVICE to get a video position? LOCATION_SERVICE is designed to pinpoint the location of a device. See Link.

-3
source

Source: https://habr.com/ru/post/900491/


All Articles