Add null check for the media player when surface texture is available.

- Call to MediaPlayer.create() method can return null, and hence we need
to check the return value before trying access the media player.

Change-Id: I4a5e0edbd6db21b678efb05ea733187f34185432
Fix: 36668356
Test: make RunSettingsRoboTests
This commit is contained in:
Doris Ling
2017-03-28 11:14:34 -07:00
parent 32924e2f58
commit 6709b6d399
2 changed files with 74 additions and 1 deletions

View File

@@ -24,6 +24,7 @@ import android.media.MediaPlayer;
import android.media.MediaPlayer.OnInfoListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.net.Uri;
import android.support.annotation.VisibleForTesting;
import android.util.AttributeSet;
import android.view.Surface;
import android.view.TextureView;
@@ -73,7 +74,11 @@ public class FingerprintLocationAnimationVideoView extends TextureView
mTextureToDestroy.release();
mTextureToDestroy = null;
}
mMediaPlayer = MediaPlayer.create(mContext, videoUri);
mMediaPlayer = createMediaPlayer(mContext, videoUri);
if (mMediaPlayer == null) {
// MediaPlayer.create() method can return null
return;
}
mMediaPlayer.setSurface(new Surface(surfaceTexture));
mMediaPlayer.setOnPreparedListener(new OnPreparedListener() {
@Override
@@ -113,6 +118,11 @@ public class FingerprintLocationAnimationVideoView extends TextureView
});
}
@VisibleForTesting
MediaPlayer createMediaPlayer(Context context, Uri videoUri) {
return MediaPlayer.create(mContext, videoUri);
}
protected static Uri resourceEntryToUri (Context context, int id) {
Resources res = context.getResources();
return Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" +