Error in opening streaming video

只谈情不闲聊 提交于 2019-12-12 11:35:01

问题


I'm trying to open video stream by giving the url of the video. I'm using VideoView.Here is my code:

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.

On executing this, I'm not getting any error but I'm getting a dialog box with title "cannot play video" and with message "Sorry, this video can't be played". Any ideas why my code is not working?


回答1:


First check that you have added INTERNET permission in your manifest.

Next check that what is the extension of your video format.

This link shows what files Android phones and tablets support, with both codec and filename extension information provided. However, an Android application can use media codecs either provided by any Android-powered device, or additional media codecs developed by third-party companies. Therefore, if you want to play videos on Android, find a multi-format video player or convert videos to Android compatible formats.

See this Android Supported Media Formats link.




回答2:


Change your URL from :

http://172.16.154.106:8080

To :

http://172.16.154.106:8080/

If android device supports this format than it will be ok.



来源:https://stackoverflow.com/questions/14354933/error-in-opening-streaming-video

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!