Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2ad201e0 authored by Raff Tsai's avatar Raff Tsai
Browse files

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: default avatarHoff Cheng <hoffc@qti.qualcomm.com>
parent 3c2d1680
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -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) {