Video Player Does not Play the Video Every time

こ雲淡風輕ζ 提交于 2019-12-14 01:48:50

问题


I am working on an application in which I have to use Android Video Player. I am giving this Player a URI, that sometime runs and some time does not. URI is generated at run time according to a defined procedure.

I get the following error in logcat when video does not get played.

03-30 12:58:42.918: D/MediaPlayer(4948): Couldn't open file on client side, trying server side
03-30 12:58:43.516: E/MediaPlayer(4948): error (1, -1004)
03-30 12:58:43.516: E/MediaPlayer(4948): Error (1,-1004)
03-30 12:58:43.520: D/VideoView(4948): Error: 1,-1004

I am unable to understand this error. Please if anyone can explain this to me. Is it an issue at my (VideoPlayer's) end or Server end..???

The Code am using for Video Player is as follows:

    String url = getIntent().getExtras().getString("videourl");
    VideoView videoView = (VideoView) findViewById(R.id.videoview);
    MediaController mediaController = new MediaController(this);
    mediaController.setAnchorView(videoView);
    Uri video = Uri.parse(url);
    videoView.setMediaController(mediaController);
    videoView.setVideoURI(video);
    videoView.start();

One thing more that, when video is not played, I get an Error dialog which shows:

"Sorry! This video cannot be played."with an "ok" button. When I press the button, the view does not pops back to my app's previous window, rather it remain on VideoPlayer screen and I have to press back button twice to get back to the previous view. Why is it so..??? Any helps about the explained issues is much much appreciated.


回答1:


form log -1004 means: public static final int MEDIA_ERROR_IO

for me, this works always:

    Uri video = Uri.parse(url);
    mediaController = new MediaController(this);
    mediaController.setAnchorView(videoView);
    videoView.requestFocus();
    videoView.setMediaController(mediaController);
    videoView.setVideoURI(video);

    videoView.setOnPreparedListener(new OnPreparedListener()
    {

        @Override
        public void onPrepared(MediaPlayer arg0)
        {
            videoView.start();
        }
    });


来源:https://stackoverflow.com/questions/9939243/video-player-does-not-play-the-video-every-time

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