Skip to content

Instantly share code, notes, and snippets.

@blundell
Created January 21, 2014 12:29
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save blundell/8539133 to your computer and use it in GitHub Desktop.
Save blundell/8539133 to your computer and use it in GitHub Desktop.
Adding a progress spinner to a video view for before it starts or whilst it is buffering.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<VideoView
android:id="@+id/my_video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center" />
<ProgressBar
android:id="@+id/my_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"
android:layout_gravity="center" />
</FrameLayout>
__________________________________________________________________________________
VideoView videoView = (VideoView) findViewById(R.id.my_video_view);
ProgressBar spinnerView = (ProgressBar) findViewById(R.id.my_spinner);
videoView.setOnInfoListener(onInfoToPlayStateListener);
private final OnInfoListener onInfoToPlayStateListener = new OnInfoListener() {
@Override
public boolean onInfo(MediaPlayer mp, int what, int extra) {
if (MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START == what) {
spinnerView.setVisibility(View.GONE);
}
if (MediaPlayer.MEDIA_INFO_BUFFERING_START == what) {
spinnerView.setVisibility(View.VISIBLE);
}
if (MediaPlayer.MEDIA_INFO_BUFFERING_END == what) {
spinnerView.setVisibility(View.VISIBLE);
}
return false;
}
};
@cadesalaberry
Copy link

Note that it is only available since API Level 17.

@khantpd01405
Copy link

thanks bro, very helpful!

@Vikramsinh
Copy link

Bro, Because of it Android throw below exception always ...
E/MediaPlayer: setDataSource: IOException! uri=https://(Link of video).m3u8
java.io.FileNotFoundException: No content provider: https://(Link of video).m3u8

@HudiDev
Copy link

HudiDev commented Nov 15, 2018

Super Helpful 👍

@martinwangai
Copy link

Very helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment