user3477175
user3477175

Reputation: 17

How to Remove Related Videos in Android Youtube API for Youtube Videos?

I have developed Android with Youtube videos. After the video got completed, I am getting suggestions from youtube like (you may also like these videos). I want to remove the Related videos in Youtube videos.

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;
        }

Please provide solution on this, I have added small snippet above, How to disable them and click on these videos open Youtube app as well.How to prevent it from open youtube app/ youtube website while clicking them.

Is it acceptable by youtube with AdMob? Thanks in advance.

Upvotes: 1

Views: 751

Answers (2)

mystic
mystic

Reputation: 85

you can solve this problem if you call this function in onVideoEnded() function.

Player.cueVideo("videoid")

Upvotes: 0

ycannot
ycannot

Reputation: 1947

you can overcome this problem if you call this function in onVideoEnded() function.

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

Upvotes: 0

Related Questions