Fix Settings crashed on tapping on notification animation video

- When preference goes back from pause state, it doesn't call through
onBindViewHolder, caused surface view doesn't attach to Mediaplayer.
Call attachView in initAnimationController and set SurfaceView to
MediaPlayer when onSurfaceTextureUpdated to fix the issue.

Fixes: 143905693
Test: manual, robolectric
Change-Id: I0eceead2e4c90ca176ef0f35937898f9b9be6232
This commit is contained in:
Raff Tsai
2019-11-05 13:24:08 +08:00
parent ee9f1be50a
commit 9547fa73cc
4 changed files with 81 additions and 9 deletions

View File

@@ -33,6 +33,7 @@ import android.view.View;
class MediaAnimationController implements VideoPreference.AnimationController {
private MediaPlayer mMediaPlayer;
private boolean mVideoReady;
private Surface mSurface;
MediaAnimationController(Context context, int videoId) {
final Uri videoPath = new Uri.Builder().scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
@@ -86,10 +87,7 @@ class MediaAnimationController implements VideoPreference.AnimationController {
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width,
int height) {
if (mMediaPlayer != null) {
final Surface surface = new Surface(surfaceTexture);
mMediaPlayer.setSurface(surface);
}
setSurface(surfaceTexture);
}
@Override
@@ -105,6 +103,7 @@ class MediaAnimationController implements VideoPreference.AnimationController {
@Override
public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
setSurface(surfaceTexture);
if (mVideoReady) {
if (preview.getVisibility() == View.VISIBLE) {
preview.setVisibility(View.GONE);
@@ -146,4 +145,11 @@ class MediaAnimationController implements VideoPreference.AnimationController {
mMediaPlayer.start();
}
}
private void setSurface(SurfaceTexture surfaceTexture) {
if (mMediaPlayer != null && mSurface == null) {
mSurface = new Surface(surfaceTexture);
mMediaPlayer.setSurface(mSurface);
}
}
}