代码:
path = "httplive://<host>/moviets/index.m3u8";
// Create a new media player and set the listeners
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setDataSource(path);
mMediaPlayer.setOnErrorListener(this);
mMediaPlayer.setDisplay(holder);
mMediaPlayer.prepare(); // Crashes here. prepareAsync() does not help either
mMediaPlayer.setOnBufferingUpdateListener(this);
mMediaPlayer.setOnCompletionListener(this);
mMediaPlayer.setOnPreparedListener(this);
mMediaPlayer.setOnVideoSizeChangedListener(this);
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mMediaPlayer.start();
堆栈追踪:
ERROR/MediaPlayer(1349): error (100, 0)
ERROR/MediaPlayerDemo(1349): error: Prepare failed.: status=0x64
ERROR/MediaPlayerDemo(1349): java.io.IOException: Prepare failed.: status=0x64
ERROR/MediaPlayerDemo(1349): at android.media.MediaPlayer.prepare(Native Method)
ERROR/MediaPlayerDemo(1349): at com.example.Example.VideoPlayerActivity.playVideo(VideoPlayerActivity.java:81)
ERROR/MediaPlayerDemo(1349): at com.example.Example.VideoPlayerActivity.surfaceCreated(VideoPlayerActivity.java:138)
ERROR/MediaPlayerDemo(1349): at android.view.SurfaceView.updateWindow(SurfaceView.java:565)
ERROR/MediaPlayerDemo(1349): at android.view.SurfaceView.access$000(SurfaceView.java:84)
ERROR/MediaPlayerDemo(1349): at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:173)
ERROR/MediaPlayerDemo(1349): at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:590)
ERROR/MediaPlayerDemo(1349): at android.view.ViewRoot.performTraversals(ViewRoot.java:1325)
ERROR/MediaPlayerDemo(1349): at android.view.ViewRoot.handleMessage(ViewRoot.java:1944)
ERROR/MediaPlayerDemo(1349): at android.os.Handler.dispatchMessage(Handler.java:99)
ERROR/MediaPlayerDemo(1349): at android.os.Looper.loop(Looper.java:126)
ERROR/MediaPlayerDemo(1349): at android.app.ActivityThread.main(ActivityThread.java:3997)
ERROR/MediaPlayerDemo(1349): at java.lang.reflect.Method.invokeNative(Native Method)
ERROR/MediaPlayerDemo(1349): at java.lang.reflect.Method.invoke(Method.java:491)
ERROR/MediaPlayerDemo(1349): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
ERROR/MediaPlayerDemo(1349): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
ERROR/MediaPlayerDemo(1349): at dalvik.system.NativeStart.main(Native Method)
DEBUG/MediaPlayerDemo(1349): surfaceChanged called
logcat的:
DEBUG/MediaPlayerDemo(1349): surfaceCreated called
INFO/System.out(1349): the path is httplive://192.168.0.196/moviets/index.m3u8
INFO/StagefrightPlayer(1312): setDataSource('httplive://192.168.0.196/moviets/index.m3u8')
INFO/LiveSession(1312): onConnect 'http://192.168.0.196/moviets/index.m3u8'
INFO/NuHTTPDataSource(1312): connect to 192.168.0.196:80/moviets/index.m3u8 @0
INFO/NuHTTPDataSource(1312): connect to 192.168.0.196:80/moviets/index.m3u8 @0
INFO/NuHTTPDataSource(1312): connect to 192.168.0.196:80/moviets/file5.ts @0
INFO/avc_utils(1312): found AVC codec config (320 x 240, Baseline-profile level 3.0)
INFO/ESQueue(1312): found something resembling an AAC syncword at offset 1017
INFO/NuHTTPDataSource(1312): connect to 192.168.0.196:80/moviets/file6.ts @0
INFO/ESQueue(1312): found AAC codec config (48000 Hz, 7 channels)
INFO/ESQueue(1312): [ 06-26 17:37:17.397 1312:0x550 F/ESQueue ]
INFO/ESQueue(1312): frameworks/base/media/libstagefright/mpeg2ts/ESQueue.cpp:255 Should not be here.
INFO/DEBUG(31): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
INFO/DEBUG(31): Build fingerprint: 'generic/sdk/generic:3.0/HONEYCOMB/104254:eng/test-keys'
INFO/DEBUG(31): pid: 1312, tid: 1360 >>> /system/bin/mediaserver <<<
INFO/DEBUG(31): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadbaad
INFO/DEBUG(31): r0 deadbaad r1 0000000c r2 00000027 r3 00000000
INFO/DEBUG(31): r4 00000080 r5 aff46658 r6 00000007 r7 00000000
INFO/DEBUG(31): r8 a2b72589 r9 00012a6c 10 00100000 fp 00000001
INFO/DEBUG(31): ip ffffffff sp 4060f488 lr aff193e9 pc aff15f58 cpsr 00000030
INFO/NuHTTPDataSource(1312): connect to 192.168.0.196:80/moviets/file7.ts @0
INFO/DEBUG(31): #00 pc 00015f58 /system/lib/libc.so
INFO/DEBUG(31): #01 pc 00001466 /system/lib/liblog.so (__android_log_assert)
INFO/DEBUG(31): libc base address: aff00000
让我感到困惑的是“找到AAC编解码器配置”这一行,而视频文件包含mp3编码。这是正常的还是我的Android客户端错误地将mp3视为aac?仅供参考,其他带有aac编码的视频在客户端播放正常
有任何线索吗?
答案 0 :(得分:1)
这似乎是Honeycomb模拟器中的一个错误,其中Android错误地将mp3流检测为aac。另一方面,FFmpeg正确检测mp3流,如下所示
ffmpeg -i file6.ts
Stream #0.1[0x101]: Audio: mp3, 48000 Hz, 2 channels, s16, 192 kb/s
不幸的是,Android认为它是AAC
INFO/avc_utils(1312): found AVC codec config (320 x 240, Baseline-profile level 3.0)
INFO/ESQueue(1312): found something resembling an AAC syncword at offset 1017
INFO/NuHTTPDataSource(1312): connect to <ip>:<port>/moviets/file6.ts @0
INFO/ESQueue(1312): found AAC codec config (48000 Hz, 7 channels)
INFO/ESQueue(1312): [ 06-26 17:37:17.397 1312:0x550 F/ESQueue ]
INFO/ESQueue(1312): frameworks/base/media/libstagefright/mpeg2ts/ESQueue.cpp:255 \
Should not be here.
解决方法是使用AAC编码。如果您使用的是ffmpeg,请使用-acodec libfaac
选项。这适用于我们的项目,因为我们可以自由选择源视频格式。但这可能不一定是你的情况。