I am adding a basic video player with VideoView and MediaController.
The SeekBar provided by the MediaController stops at 0:02 min while the video is playing till the end. I have tried this on 3 different devices with different video lengths.
How to ensure that SeekBar progress and time are in sync with the video?
Here is the relevant code:
VideoPlayerDialog.java
videoView.setVisibility(View.VISIBLE);
MediaController mediaController = new MediaController(getContext());
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
lp.gravity = Gravity.BOTTOM;
mediaController.setLayoutParams(lp);
((ViewGroup) mediaController.getParent()).removeView(mediaController);
((FrameLayout) findViewById(R.id.videoViewWrapper)).addView(mediaController);
videoView.setMediaController(mediaController);
videoView.setVideoURI(imageUri);
videoView.requestFocus();
dialog_image_preview.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black87">
<uk.co.senab.photoview.PhotoView
android:id="@+id/photo_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true" />
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/videoViewWrapper"
android:layout_centerInParent="true"
android:layout_margin="30dp">
<VideoView
android:id="@+id/videoplayer"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</FrameLayout>
<ImageButton
android:id="@+id/close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@drawable/circular_button_material"
android:elevation="10dp"
android:padding="5dp"
android:src="@drawable/ic_close" />
</RelativeLayout>