如何删除Android Youtube API中的相关视频的Youtube视频?

6ie5vjzr  于 2023-01-15  发布在  Android
关注(0)|答案(2)|浏览(197)

我用Youtube视频开发了Android。视频完成后,我从Youtube上得到了一些建议(你可能也喜欢这些视频)。我想删除Youtube视频中的相关视频。

this.video_youtube_player =(YouTubePlayerView) findViewById(R.id.video_youtube_player);
        this.onInitializedListinner =  new YouTubePlayer.OnInitializedListener(){
            @Override
            public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
                youTubePlayer.loadVideo(new YouTubeHelper().extractVideoIdFromUrl(original));
                youTubePlayer.setPlayerStyle(YouTubePlayer.PlayerStyle.MINIMAL);

                youTubePlayer.setPlayerStateChangeListener(new YouTubePlayer.PlayerStateChangeListener() {
                    @Override
                    public void onLoading() {                    }

                    @Override
                    public void onLoaded(String s) {                  }

                    @Override
                    public void onAdStarted() {                  }

                    @Override
                    public void onVideoStarted() {                }

                    @Override
                    public void onVideoEnded() {                    }

                    @Override
                    public void onError(YouTubePlayer.ErrorReason errorReason) {                   }

                });
            }

            @Override
            public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {

            }
        };
        video_youtube_player.initialize(Global.Youtube_Key,onInitializedListinner);
    }
    public class YouTubeHelper {

        final String youTubeUrlRegEx = "^(https?)?(://)?(www.)?(m.)?((youtube.com)|(youtu.be))/";
        final String[] videoIdRegex = { "\\?vi?=([^&]*)","watch\\?.*v=([^&]*)", "(?:embed|vi?)/([^/?]*)", "^([A-Za-z0-9\\-]*)"};

        public String extractVideoIdFromUrl(String url) {
            String youTubeLinkWithoutProtocolAndDomain = youTubeLinkWithoutProtocolAndDomain(url);

            for(String regex : videoIdRegex) {
                Pattern compiledPattern = Pattern.compile(regex);
                Matcher matcher = compiledPattern.matcher(youTubeLinkWithoutProtocolAndDomain);

                if(matcher.find()){
                    return matcher.group(1);
                }
            }

            return null;
        }

请提供解决方案,我已经添加了上面的小片段,如何禁用它们,并点击这些视频打开YouTube应用程序以及。如何防止它打开YouTube应用程序/ YouTube网站,而点击它们。
AdMob的youtube能接受吗?提前感谢。

deyfvvtc

deyfvvtc1#

如果您在**onVideoEnded()**函数中调用此函数,则可以克服此问题。

private void seekToZero(YouTubePlayer player){
    player.seekToMillis(0)
    player.play()
    player.pause()
}
snz8szmq

snz8szmq2#

如果在onVideoEnded()函数中调用此函数,则可以解决此问题。
播放器. cue视频(“视频对象”)

相关问题