如何使用适配器在应用程序内播放youtube视频

时间:2016-12-09 07:02:26

标签: android ytplayerview

您好我想在我的应用程序中播放YouTube视频,而我正在使用THIS LIBRARY 。我正在初始化Adapter内的所有值,所以我不能`扩展YouTubeBaseActivity类。请给我一个实现目标的好方法。就像其他应用程序一样,我也想在应用程序中播放youtube视频。 这是我的适配器代码

 Pattern compiledPattern = Pattern.compile(pattern);
                Matcher matcher = compiledPattern.matcher(thumbanil_url);
                if (matcher.find()) {
                    value_id = matcher.group();
                    ((DemoViewHolderThird) holder).demoThirdItemInitView.youtubePlayerView.setAutoPlayerHeight(context);
                    ((DemoViewHolderThird) holder).demoThirdItemInitView.youtubePlayerView.initialize(value_id, new YoutubePlayerView.YouTubeListener() {


                        @Override
                        public void onReady() {
                            ((DemoViewHolderThird) holder).demoThirdItemInitView.youtubePlayerView.play();
                            JLog.i("onReady()");
                        }

                        @Override
                        public void onStateChange(YoutubePlayerView.STATE state) {
                           // ((DemoViewHolderThird) holder).demoThirdItemInitView.youtubePlayerView.play();
                        }

                        @Override
                        public void onPlaybackQualityChange(String arg) {
                            //((DemoViewHolderThird) holder).demoThirdItemInitView.youtubePlayerView.play();
                        }

                        @Override
                        public void onPlaybackRateChange(String arg) {
                            //((DemoViewHolderThird) holder).demoThirdItemInitView.youtubePlayerView.play();
                        }

                        @Override
                        public void onError(String arg) {
                            //((DemoViewHolderThird) holder).demoThirdItemInitView.youtubePlayerView.play();
                        }

                        @Override
                        public void onApiChange(String arg) {
                        }

                        @Override
                        public void onCurrentSecond(double second) {

                        }

                        @Override
                        public void onDuration(double duration) {

                        }

                        @Override
                        public void logs(String log) {

                        }
                    });


                }

1 个答案:

答案 0 :(得分:0)

您可以使用以下演示集成YouTube和播放视频 How to Play YouTube Video in Android App