Created
January 21, 2014 12:29
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Super Helpful 👍