【发布时间】:2012-01-31 04:04:42
【问题描述】:
我正在尝试流式传输一些视频:使用 3gp 一切正常流畅,但是当我尝试 mp4 时(我使用了几个视频进行测试,包括这个,这绝对应该是好的和有效的 - commonsware.com/misc/test.mp4),我有一个例外。
我有一个 android 2.2 平板电脑进行测试,我的问题是因为这个吗? mp4-via-http 可以在 android 2.3 或更高版本上运行吗?还是有什么我不知道的特定于 mp4 的准备步骤?现在我只需执行以下操作:
@Override
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
gMp=new MediaPlayer();
gMp.setDisplay(hndlr);
try {
gMp.setDataSource(this, Uri.parse("http://commonsware.com/misc/test.mp4"));
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
gMp.prepareAsync();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
gMp.start();
}
这是我的错误日志:
I/ActivityManager( 107): Starting activity: Intent { act=android.intent.action.MAIN flg=0x10000000 cmp=com.video.mp/.VideoSharingViaMPActivity }
I/ActivityManager( 107): Start proc com.video.mp for activity com.video.mp/.VideoSharingViaMPActivity: pid=746 uid=10055 gids={1015, 3003}
D/dalvikvm( 746): GC_FOR_MALLOC freed 576 objects / 46928 bytes in 37ms
I/dalvikvm-heap( 746): Grow heap (frag case) to 3.549MB for 1000016-byte allocation
D/dalvikvm( 746): GC_FOR_MALLOC freed 170 objects / 8488 bytes in 44ms
D/MediaPlayer( 746): Couldn't open file on client side, trying server side
V/MediaPlayerService( 67): Client(3) constructor
V/MediaPlayerService( 67): Create new client(3) from pid 746, url=http://commonsware.com/misc/test.mp4, connId=3
V/MediaPlayerService( 67): setDataSource(http://commonsware.com/misc/test.mp4)
V/MediaPlayerService( 67): player type = 1
V/MediaPlayerService( 67): create PVPlayer
V/MediaPlayerService( 67): setDataSource
V/MediaPlayerService( 67): [3] setVideoSurface(0x3cfd8)
V/MediaPlayerService( 67): [3] setAudioStreamType(3)
V/MediaPlayerService( 67): [3] prepareAsync
V/MediaPlayerService( 67): [3] notify (0x3b2f8, 3, 0, 0)
I/PlayerDriver( 67): buffering (1)
V/MediaPlayerService( 67): [3] notify (0x3b2f8, 3, 1, 0)
V/MediaPlayerService( 67): [3] notify (0x3b2f8, 200, 1, 26)
W/MediaPlayer( 746): info/warning (1, 26)
E/PlayerDriver( 67): Command PLAYER_INIT completed with an error or info PVMFErrResource
V/MediaPlayerService( 67): [3] notify (0x3b2f8, 100, 1, -17)
W/PlayerDriver( 67): PVMFInfoErrorHandlingComplete
E/MediaPlayer( 746): error (1, -17)
W/System.err( 746): java.io.IOException: Prepare failed.: status=0x1
W/System.err( 746): at android.media.MediaPlayer.prepare(Native Method)
W/System.err( 746): at com.video.mp.VideoSharingViaMPActivity.surfaceCreated(VideoSharingViaMPActivity.java:146)
【问题讨论】:
-
请贴出错误信息。
-
编辑了帖子并添加了一些内容,似乎我误解了,它在准备时失败(或 prepareAsync,我得到了相同的结果)
-
您不应在 prepareAsync 之后立即调用
gMp.start(),而应通过gMp.setOnPreparedListener()添加MediaPlayer.OnPreparedListener。在这个监听器中是时候启动你的播放器了。
标签: android http streaming media-player mp4