Settings: fix the NullPointerException when initiating media player
If the input media resource is invalid, MediaPlayer create calling may fail and returns null, so trigger one NullPointerException. Add the null pointer judegement when calling seekto and so on. Test: manual Fixes: 130032215 Change-Id: I38cb08584aa4e4c2ce4dc58a5a095960c7bd1948 Signed-off-by: Hoff Cheng <hoffc@qti.qualcomm.com>
This commit is contained in:
@@ -220,6 +220,9 @@ public class VideoPreference extends Preference {
|
||||
private void initMediaPlayer() {
|
||||
if (mMediaPlayer == null) {
|
||||
mMediaPlayer = MediaPlayer.create(mContext, mVideoPath);
|
||||
// when the playback res is invalid or others, MediaPlayer create may fail
|
||||
// and return null, so need add the null judgement.
|
||||
if (mMediaPlayer != null) {
|
||||
mMediaPlayer.seekTo(0);
|
||||
mMediaPlayer.setOnSeekCompleteListener(mp -> mVideoReady = true);
|
||||
mMediaPlayer.setOnPreparedListener(mediaPlayer -> mediaPlayer.setLooping(true));
|
||||
@@ -228,6 +231,7 @@ public class VideoPreference extends Preference {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void releaseMediaPlayer() {
|
||||
if (mMediaPlayer != null) {
|
||||
|
Reference in New Issue
Block a user