异常mOnBufferingUpdateListener为null。无法发送MEDIA_BUFFERING_UPDATE消息

时间:2013-06-21 13:09:31

标签: android

我正在使用Surface视图并想播放视频。但是视频不会多次显示其给出错误消息“mOnBufferingUpdateListener为null。无法发送MEDIA_BUFFERING_UPDATE消息。”

请建议我解决这个问题。

@SuppressWarnings("deprecation")
private void createSurface() {
    try {
        holder = surfaceView.getHolder();
        holder.addCallback(this);
        holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        mMediaPlayer = new MediaPlayer();
        mMediaPlayer.setDisplay(holder);
    } catch(Exception e) {
        Log.v("NB", "Exception at ::" + e.getMessage());
    }
}

private void releaseMediaPlayer() {
    if (mMediaPlayer != null) {
        mMediaPlayer.stop();
        mMediaPlayer.release();
        mMediaPlayer = null;
    }
}

private void playVideo() {
    try {
        if(videoPath!=null) {
            mMediaPlayer.setDataSource(videoPath);
            mMediaPlayer.prepare();
        }
    }
    catch (IllegalArgumentException e)
    {e.printStackTrace();}

    catch (IllegalStateException e)
    {e.printStackTrace();}

    catch (IOException e)
    {e.printStackTrace();}

    mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mMediaPlayer.start();

    mMediaPlayer.setOnCompletionListener(new OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mp) {
            releaseMediaPlayer();
            //finish();
        }
    });
}


@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {

}

@Override
public void surfaceCreated(SurfaceHolder holder) {
    playVideo();
}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
}

@Override
protected void onDestroy() {
    super.onDestroy();
    releaseMediaPlayer();
}

提前致谢。

0 个答案:

没有答案