bilibili / ijkplayer

Android/iOS video player based on FFmpeg n3.4, with MediaCodec, VideoToolbox support.
GNU General Public License v2.0
32.54k stars 8.13k forks source link

NullPointerException:android.graphics.Rect android.media.TimedText.getBounds() #2754

Open liwshuo opened 7 years ago

liwshuo commented 7 years ago

java.lang.NullPointerException: Attempt to invoke virtual method 'android.graphics.Rect android.media.TimedText.getBounds()' on a null object reference at tv.danmaku.ijk.media.player.AndroidMediaPlayer$AndroidMediaPlayerListenerHolder.onTimedText(AndroidMediaPlayer.java:427) at android.media.MediaPlayer$EventHandler.handleMessage(MediaPlayer.java:2895) at android.os.Handler.dispatchMessage(Handler.java:111) at android.os.Looper.loop(Looper.java:194) at android.os.HandlerThread.run(HandlerThread.java:61) 在AndroidMediaPlayer的AndroidMediaPlayerListenerHolder的onTimedText回调接口中,TimedText可能为空,导致NullPointerException。

liwshuo commented 7 years ago
           case MEDIA_TIMED_TEXT:
                OnTimedTextListener onTimedTextListener = mOnTimedTextListener;
                if (onTimedTextListener == null)
                    return;
                if (msg.obj == null) {
                    onTimedTextListener.onTimedText(mMediaPlayer, null);
                } else {
                    if (msg.obj instanceof Parcel) {
                        Parcel parcel = (Parcel)msg.obj;
                        TimedText text = new TimedText(parcel);
                        parcel.recycle();
                        onTimedTextListener.onTimedText(mMediaPlayer, text);
                    }
                }
                return;

在MediaPlayer的源码里,TimedText参数是可能为null的,在回调的时候还是应该最好判断一下的吧.

public void onTimedText(MediaPlayer mp, TimedText text) {
            AndroidMediaPlayer self = (AndroidMediaPlayer)this.mWeakMediaPlayer.get();
            if(self != null) {
                IjkTimedText ijkText = new IjkTimedText(text.getBounds(), text.getText());
                AndroidMediaPlayer.this.notifyOnTimedText(ijkText);
            }
        }
raymond1012 commented 7 years ago

want to fix it in next version