Android Videoview Clear Display After Stopplayback()
Solution 1:
For me, what worked was simply to hide then show the VideoView
using setVisibility
.
publicvoidclearCurrentFrame() {
videoView.setVisibility(GONE);
videoView.setVisibility(VISIBLE);
}
This was because I wanted the VideoView
to become transparent, not be a solid colour. Setting the background to transparent doesn't work -- the video frame still shows.
Solution 2:
The solution I settled on, unless someone can offer a better one, is to use setBackgroundResource
, which seems oddly named since it appears to change the foreground resource.
publicViewonCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
...
videoViewer.setBackgroundResource(R.drawable.viewer_background);
...
}
publicvoidonItemClick(AdapterView<?> parent, View view, int position, long id) {
if (videoViewer != null) {
videoViewer.stopPlayback();
// Set the background back to the drawable resource to clear the current video when switching to a new one.
videoViewer.setBackgroundResource(R.drawable.viewer_background);
videoViewer.setVideoURI(Uri.parse("http://my_vido_url/playlist.m3u8"));
}
}
privateclassOnPreparedListenerimplementsMediaPlayer.OnPreparedListener {
@OverridepublicvoidonPrepared(MediaPlayer mp) {
videoViewer.start();
// Clear the background resource when the video is prepared to play.
videoViewer.setBackgroundResource(0);
}
}
The drawable I'm referencing is a simple layer-list
with a custom blue background and a centered logo image.
drawable\viewer_background.xml:
<?xml version="1.0" encoding="utf-8"?><layer-listxmlns:android="http://schemas.android.com/apk/res/android" ><item><shapeandroid:shape="rectangle"><solidandroid:color="@color/custom_blue" /></shape></item><item><bitmapandroid:src="@drawable/img_logo"android:gravity="center" /></item></layer-list>
Alternatively I was also able to use setZOrderOnTop
to control where the surface view is placed (you could also define another view on top of the VideoViewer and toggle the visibility that way):
videoViewer.setZOrderOnTop(false);
videoViewer.setZOrderOnTop(true);
Alternatively I could also use setBackgoundColor
to accomplish the same thing as setBackgroundResource
:
videoViewer.setBackgroundColor(getResources().getColor(R.color.custom_blue));
videoViewer.setBackgroundColor(Color.TRANSPARENT);
Solution 3:
just this code:
videoView.setVideoURI(null);
Solution 4:
Well, for me none of the solutions from this thread worked, so I tried something else and below is the solution that worked for me,
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
mVideoViewPlayList.setVisibility(View.GONE);
mVideoViewPlayList.setVisibility(View.VISIBLE);
mVideoViewPlayList.setVideoURI(Uri.parse(path));
}
}, 500);
Solution 5:
You can do like this;
videoView.stopPlayBack();
videoView.seekTo(0);
hope that may help you
Post a Comment for "Android Videoview Clear Display After Stopplayback()"