使用Youtube Player API播放不同的youtube视频 [英] Playing different youtube videos using Youtube Player API

查看:137
本文介绍了使用Youtube Player API播放不同的youtube视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用适用于Android的Youtube Player API播放视频,并选择listview中的视频之一(视频之前已解析json等).当我只能播放选择的listview的第一个视频时,就会出现问题,因为当我单击listView的其他元素时,播放器视图不会改变.这是重要的代码:

I´m using the Youtube Player API for Android to play videos selecting one of these in a listview (videos are previously got parsing json etc etc). The problem comes when I can only play the first video of the listview that I select, cause the player view doesnt change when I do click in a different element of the listView. This is the important code:

 lista.setOnItemClickListener(new OnItemClickListener(){

            @Override
            public void onItemClick(AdapterView<?> pariente, View view, 
                    int posicion, long id) {

                Video chosen = (Video)pariente.getItemAtPosition(posicion); 
                String urlVideo = chosen.getUrl();
                String aux = getYoutubeVideoId(urlVideo);
                URL_VIDEO = aux;

                youTubeView.initialize(KEY_DEVELOPER, new YouTubePlayer.OnInitializedListener() {

                    @Override
                    public void onInitializationFailure(Provider arg0,
                            YouTubeInitializationResult arg1) {
                        // TODO Auto-generated method stub
                        Log.d("DEPURANDO: ERROR AL VISUALIZAR", URL_VIDEO);

                    }

                    @Override
                    public void onInitializationSuccess(Provider arg0,
                            YouTubePlayer player, boolean wasRestored) {
                        // TODO Auto-generated method stub
                        if(!wasRestored){       
                            Log.d("YOUTUBE", "URL: " + URL_VIDEO);
                            player.cueVideo(URL_VIDEO);
                        }
                    }
                });
            }


我知道问题是因为播放器无法初始化两次,所以执行只在OnInitializationSucess中输入了一次(我测试过),因此只能播放第一个视频.如何解决这个问题?


I understand the problem comes because the player can't be initialized twice, so the execution only enter once in OnInitializationSucess (I tested) and therefore only plays the first video. how to solve this problem?

推荐答案

检查YouTube API示例的最新版本

Check the last version of the YouTube API Samples

YouTube API示例

我认为该示例可能对您有用:

I think this sample can be useful to you:

查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆