Unable to play YouTube Videos

孤街醉人 提交于 2019-12-12 04:04:51

问题


Please have a look at the following code

private class IntroVideoHandler implements OnClickListener
    {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            MediaPlayer mp = new MediaPlayer();
            try {
                mp.setDataSource("http://www.youtube.com/watch?v=Cb7QJwQ58T0");
                mp.prepareAsync();
                mp.start();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } 


        }

Here, I am unable to play the youtube video either in simulator or phone. I get the following error

08-22 14:34:47.176: E/MediaPlayer(471): start called in state 4
08-22 14:34:47.176: E/MediaPlayer(471): error (-38, 0)
08-22 14:34:47.306: E/MediaPlayer(471): Error (-38,0)
08-22 14:34:56.426: E/MediaPlayer(471): error (1, -2147483648)
08-22 14:34:56.426: E/MediaPlayer(471): Error (1,-2147483648)

Why is this?


回答1:


see this API

And

You can not play youtube video directly in video view this way.. you have below option to play it.

1) load this url in webview

2) pass youtube video id to youtube application.

3) get RTSP url from video id and play in videoView



来源:https://stackoverflow.com/questions/18375930/unable-to-play-youtube-videos

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