How to capture the play video action in YouTube player for Android

rainman

I have YouTube player embedded in an Android application. I play videos using the following class:

public class YoutubePlayerActivity extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener {

    private static final String TAG =  YoutubePlayerActivity.class.getSimpleName();

    private YouTubePlayerView playerView;
    private Toolbar toolbar;
    private int minuto;


    @Override
    protected void onCreate(Bundle savedInstanceState) {

        Log.d(TAG , "onCreate(Bundle) - Ini ");

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_player);
        toolbar= (Toolbar) findViewById(R.id.app_bar);
      //  setSupportActionBar(toolbar);
        toolbar.setTitle(R.string.app_name);
        toolbar.setTitleTextColor(getResources().getColor(R.color.com_facebook_button_background_color_focused));

        playerView = (YouTubePlayerView) findViewById(R.id.player_view);
        playerView.initialize(DeveloperKey.DEVELOPER_KEY, this);


        Log.d(TAG , "onCreate(Bundle) - Fi ");
    }

    @Override
    public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {

        Log.d(TAG , "onInitializationSuccess(Provider, YouTubePlayer, boolean ) - Ini ");

        if(!b) {
            youTubePlayer.play();
            youTubePlayer.cueVideo(getIntent().getStringExtra("VIDEO_ID"));
            minuto =  youTubePlayer.getCurrentTimeMillis();



        }

        Log.d(TAG , "onInitializationSuccess(Provider, YouTubePlayer, boolean ) - Fi ");

    }

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

        Log.d(TAG , "onInitializationFailure(Provider, YouTubeInitializationResult) - Ini ");

        Toast.makeText(this, getString(R.string.player_failed), Toast.LENGTH_LONG).show();

        Log.d(TAG , "onInitializationFailure(Provider, YouTubeInitializationResult) - Fi ");
    }

    @Override
    public void onBackPressed () {

    }
}

I want to capture the event of clicking play video. Is there a way to capture the event of playing the video?

Rashid

to capture the button like playing, pausing you can set the youtube playback like this

playerView.setPlaybackEventListener(playbackEventListener);

where playback listener is declared like this:

private PlaybackEventListener playbackEventListener = new PlaybackEventListener()    {

    @Override
    public void onBuffering(boolean arg0) {
    }

    @Override
    public void onPaused() {
    }

    @Override
    public void onPlaying() {
    }

    @Override
    public void onSeekTo(int arg0) {
    }

    @Override
    public void onStopped() {
    }

};

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to make a Youtube player popout and play a video?

how to play Youtube Video in VLC Player

Get video play of youtube player

Intent Filter for Media Player ( Youtube Video Play)

How to play youtube video?

Play youtube individual player rather in a single for multiple YouTube Video

Xcode Swift play youtube video on Native video player?

How to implement Video Player with play/pause buttons without floating action button in flutter?

YouTube Player API hide play button, icons, & video title in iframe

YouTube JavaScript player starts to play the video when seekTo is called

YouTube IFrame Player shows 'This Video is Unavailable' when play button is pressed

Is it possible to play a video file (eg .avi) using youtube player?

how to get youtube player id and stop video

How to check if webview YouTube video player was started

How to autoplay video through YouTube Player

How to play YouTube videos in VLC Player?

Unable to play some Youtube videos using YouTube Android Player API

How to play a Vimeo video in VLC media player?

error while play youtube video android studio

Unable to get a YouTube video to play with Android Studio

Youtube Player video not loading

How to play more video on the same player with Vimeo player.js

How can I play a youtube video [selenium]

How to play youtube video from MySQL database

How to play YouTube video in WebView on Google Glass

How to play youtube video in UIWebView muted?

How to register event to Youtube video play progress?

How to play Youtube live stream video in application?

How to auto play youtube video on my app?