Have you got any display issues using VideoView?
I had too. I wrote a blog post where you can find more details about these issues and how I solved them.
FrameVideoView solves flickering and black screen issues by showing placeholder on the proper time.
Placeholder is a simple View
on top of the VideoView
. Placeholder is visisble just after onPause
is called and invisible when onResume
is called.
It allows to hide VideoView
during screen transitions which causes strange issues.
If your device is running API level 14 or higher it will use TextureView to increase video playback performance, otherwise VideoView will be used.
Step 1. Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
Step 2. Add the dependency:
dependencies {
compile 'com.github.mklimek:frame-video-view:$RELEASE_VERSION'
}
Step 3. Add view in xml:
<com.mklimek.frameviedoview.FrameVideoView
android:id="@+id/frame_video_view"
android:layout_width="@dimen/video_width"
android:layout_height="@dimen/video_height"
/>
Step 4. Setup resource and FrameVideoViewListener
:
frameVideoView = (FrameVideoView) findViewById(R.id.frameVideoView);
frameVideoView.setup(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.fb));
frameVideoView.setFrameVideoViewListener(new FrameVideoViewListener() {
@Override
public void mediaPlayerPrepared(MediaPlayer mediaPlayer) {
mediaPlayer.start();
}
@Override
void mediaPlayerPrepareFailed(MediaPlayer mediaPlayer, String error){
}
});
you can call pause, resume, looping and other methods available in MediaPlayer
.
See example for more details.