youtube视频播放后自动开始新活动

时间:2019-04-30 16:23:53

标签: youtube-api activity-finish

我需要在YouTube视频播放完毕后开始一项活动。我找到了一些代码,但我猜想它是针对媒体播放器嵌入式视频的,而不是Youtube视频的。这是我的YouTube播放器页面代码。感谢您的帮助!

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_aquaparkrestaurant_vid);
    backbtn = findViewById(R.id.backbtn);
    btnPlay = findViewById(R.id.plyyoutubebtn);
    youTubePlayerView = findViewById(R.id.youtubeplay);
    mOnIntiOnInitializedListener = new YouTubePlayer.OnInitializedListener() {

        @Override
        public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
            youTubePlayer.loadVideo("lpshX0WtSTU");
            youTubePlayer.setPlayerStyle(YouTubePlayer.PlayerStyle.CHROMELESS);
        }

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

        }

    };

    btnPlay.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            youTubePlayerView.initialize(PlayerConfig.API_KEY,mOnIntiOnInitializedListener);

            if(isPlay)
                btnPlay.setImageResource(R.drawable.ic_play_circle_outline_black_24dp);
            else
                btnPlay.setImageResource(R.drawable.ic_pause_circle_outline_black_24dp);
            isPlay = !isPlay;

        }
    });

    backbtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(AquaParkRestaurantVid.this, WhatToEatActivity.class);
            startActivity(intent);

        }
    });
}}

0 个答案:

没有答案