MediaPlayer.prepare() 失败并显示有效的 http 链接
我试图流式传输一些视频:使用 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)
I was trying to stream some videos: with 3gp everything works fine and smooth, but when I tried mp4 (I used several videos for tests, including this one, which should definitely be good and valid - commonsware.com/misc/test.mp4), I got an exception.
I have an android 2.2 tablet for testing, is my problem because of this? Will mp4-via-http work on android 2.3 or newer? Or are there any specific for mp4 preparatory steps I don't know about? Now I just do the following:
@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();
}
Here are my error logs:
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请检查这一点:在您的代码中,您有链接
http://www.commonsware.com/misc/test.mp4
而真正的链接没有www
(另外,我检查了在我的浏览器中,www
的链接不存在)。Please check this: in your code you have link
http://www.commonsware.com/misc/test.mp4
while real link is withoutwww
(also, I checked with my browser, link withwww
doesn't exist).您需要首先启动()/重置()媒体播放器。请在此处查看有效和无效状态: http://developer.android.com /reference/android/media/MediaPlayer.html#Valid_and_Invalid_States
You need to start()/reset() the Mediaplayer first. See the valid and invalid states here: http://developer.android.com/reference/android/media/MediaPlayer.html#Valid_and_Invalid_States