0

我有一个播放.mp4的应用程序的源代码,我必须让它与 HLS 一起使用。

播放了视频和声音,但我只有 .m3u8 有 2 个问题:

1)当seekTo()被激活(评论被删除)时,声音被禁用,当我想退出播放器时,它需要很长时间才能完成,并且会使应用程序崩溃。

2) setLooping 不起作用并返回Error (-38,0),尝试执行错误的 seekTo

state: mPlayer=0x1e0380, mCurrentState=0

注意:这些问题仅适用于 .M3U8

播放器代码如下:

private void playVideo() {
    doCleanUp();
    try {
        // Create a new media player and set the listeners

        mMediaPlayer = new MediaPlayer();
        mMediaPlayer.setDataSource(mFilePath);
        mMediaPlayer.setDisplay(mSurfaceHolder);       
        mMediaPlayer.prepare(); 
        mMediaPlayer.start();
        mMediaPlayer.setOnCompletionListener(this);
        mMediaPlayer.setOnVideoSizeChangedListener(this);
        mMediaPlayer.setOnPreparedListener(this);
        //mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); 
        //mMediaPlayer.seekTo(mResumePosition);
        //mMediaPlayer.setLooping(true);


    } catch (Exception e) {
        Log.e(LOG_TAG, "error: " + e.getMessage(), e);
        showErrorMessage(mErrorPlayingVideo);
        // Toast.makeText(this, "Impossible de jouer la vidéo",
        // 5000).show();
    }
}

在 setDataSource() 下激活 setLooping 时的日志:

error (-38, 0)
prepareAsync called in wrong state 0
prepareAsync_l return error =-38
error: null
java.lang.IllegalStateException
at android.media.MediaPlayer.prepare(Native Method)
at fr.niji.broadpeak.activity.BroadpeakDemoPlayer.playVideo(BroadpeakDemoPlayer.java:409)
at fr.niji.broadpeak.activity.BroadpeakDemoPlayer.onRequestFinished(BroadpeakDemoPlayer.java:585)
at fr.niji.lib.dataproxy.service.DataManager.handleResult(DataManager.java:262)
at fr.niji.lib.dataproxy.service.DataManager.onRequestFinished(DataManager.java:292)
at fr.niji.lib.dataproxy.service.ServiceHelper.handleResult(ServiceHelper.java:297)
at fr.niji.lib.dataproxy.service.ServiceHelper$EvalReceiver.onReceiveResult(ServiceHelper.java:119)
at android.os.ResultReceiver$MyRunnable.run(ResultReceiver.java:43)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:132)
at android.app.ActivityThread.main(ActivityThread.java:4126)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
at dalvik.system.NativeStart.main(Native Method)

并在代码下方:

Attempt to perform seekTo in wrong state: mPlayer=0x1e0380, 
mCurrentState=0
error (-38, 0)
Error (-38,0)
Error (-38,0)
Attempt to perform seekTo in wrong state: mPlayer=0x1e0380, mCurrentState=0
Error (-38,0)
Error (-38,0)
Attempt to perform seekTo in wrong state: mPlayer=0x1e0380, mCurrentState=0
4

2 回答 2

2

好的,我发现了问题。当您将 seekTo() 与 .m3u8 文件一起使用并且括号之间的值设置为 0 时,它不起作用,因此我在 playBackVideo() 方法中添加了一个条件:

if (mResumePosition > 0) mMediaPlayer.seekTo(mResumePosition);

所以 mResumePosition 永远不会被设置为 0 并在文件的开头播放。另外,我解决了 setLooping() 问题,在

public void onCompletion(final MediaPlayer mediaPlayer)

我添加了mMediaPlayer.release(); playVideo();

并且循环效果很好!

于 2012-05-31T08:13:28.643 回答
0

您需要检查它是否是 LIVE 案例。如果是,则循环和搜索可能不可用。

于 2012-05-30T09:56:49.087 回答