打开流式视频时出错

时间:2013-01-16 09:24:02

标签: android video-streaming android-mediaplayer

我正在尝试通过提供视频的网址来打开视频流。我正在使用VideoView。这是我的代码:

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);        
        VideoView videoView = (VideoView) findViewById(R.id.stream_video_view);
        videoView.setVisibility(View.VISIBLE);
        MediaController mc = new MediaController(this);     
        mc.setAnchorView(videoView);
        mc.setMediaPlayer(videoView);
        videoView.setMediaController(mc);
        Uri uri = Uri.parse("http://172.16.154.106:8080");
        videoView.setVideoURI(uri);
        videoView.requestFocus();
        videoView.start();
    }     
}

logcat的:

01-16 15:58:16.042: D/MediaPlayer(2054): Couldn't open file on client side, trying server side
01-16 15:58:16.078: E/MediaPlayer(2054): Unable to to create media player
01-16 15:58:16.082: W/VideoView(2054): Unable to open content: http://172.16.154.106:8080
01-16 15:58:16.082: W/VideoView(2054): java.io.IOException: setDataSource failed.: status=0x80000000
01-16 15:58:16.082: W/VideoView(2054):  at android.media.MediaPlayer._setDataSource(Native Method)
01-16 15:58:16.082: W/VideoView(2054):  at android.media.MediaPlayer.setDataSource(MediaPlayer.java:844)
01-16 15:58:16.082: W/VideoView(2054):  at android.media.MediaPlayer.setDataSource(MediaPlayer.java:806)
01-16 15:58:16.082: W/VideoView(2054):  at android.widget.VideoView.openVideo(VideoView.java:221)
01-16 15:58:16.082: W/VideoView(2054):  at android.widget.VideoView.access$2000(VideoView.java:49)
01-16 15:58:16.082: W/VideoView(2054):  at android.widget.VideoView$6.surfaceCreated(VideoView.java:465)
01-16 15:58:16.082: W/VideoView(2054):  at android.view.SurfaceView.updateWindow(SurfaceView.java:562)
01-16 15:58:16.082: W/VideoView(2054):  at android.view.SurfaceView.access$000(SurfaceView.java:82)
01-16 15:58:16.082: W/VideoView(2054):  at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:171)
01-16 15:58:16.082: W/VideoView(2054):  at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:590)
01-16 15:58:16.082: W/VideoView(2054):  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1596)
01-16 15:58:16.082: W/VideoView(2054):  at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2418)
01-16 15:58:16.082: W/VideoView(2054):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-16 15:58:16.082: W/VideoView(2054):  at android.os.Looper.loop(Looper.java:137)
01-16 15:58:16.082: W/VideoView(2054):  at android.app.ActivityThread.main(ActivityThread.java:4340)
01-16 15:58:16.082: W/VideoView(2054):  at java.lang.reflect.Method.invokeNative(Native Method)
01-16 15:58:16.082: W/VideoView(2054):  at java.lang.reflect.Method.invoke(Method.java:511)
01-16 15:58:16.082: W/VideoView(2054):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-16 15:58:16.082: W/VideoView(2054):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-16 15:58:16.082: W/VideoView(2054):  at dalvik.system.NativeStart.main(Native Method)
01-16 15:58:16.082: D/VideoView(2054): Error: 1,0
01-16 15:58:16.232: D/gralloc_goldfish(2054): Emulator without GPU emulation detected.

执行此操作时,我没有收到任何错误,但我收到一个标题为“无法播放视频”的对话框,并显示“抱歉,此视频无法播放”的消息。我的代码不起作用的任何想法?

2 个答案:

答案 0 :(得分:15)

首先检查您是否在清单中添加了INTERNET权限。

接下来检查视频格式的扩展名是什么。

link显示Android手机和平板电脑支持的文件,同时提供了编解码器和文件扩展名信息。但是,Android应用程序可以使用由任何Android设备提供的媒体编解码器,或由第三方公司开发的其他媒体编解码器。因此,如果您想在Android上播放视频,请查找多格式视频播放器或将视频转换为Android兼容格式。

请参阅此Android支持的媒体格式link

答案 1 :(得分:0)

更改您的网址:

http://172.16.154.106:8080

致:

http://172.16.154.106:8080/

如果Android设备支持这种格式,那就好了。