Search code examples
androidandroid-youtube-api

YouTube Api Standalone Player results


I use YouTube Api v3.And I use Standalone player to start new Activity with some video.

holder.playButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = YouTubeStandalonePlayer.createVideoIntent((Activity) ctx,
                    Config.YOUTUBE_API_KEY,
                    appearance,
                    100,     //after this time, video will start automatically
                    true,               //autoplay or not
                    true);             //lightbox mode or not; show the video in a small box
            ctx.startActivity(intent);
        }
    });

I wonder, if there is some way to some result of starting video and it's finishing (maybe some onDestroy method of StandaloneActivity) and how can I use it?

As I know, it good be possible with others players provided by Youtube Api, but I'd to know about Standalone one exactly.

Thanks in advance!


Solution

  • Yes, it is possible. You should replace startActivity(intent) to startActivityForResult(intent, YOUR_INTENT_CODE), and then override in your Activity method protected void onActivityResult(int requestCode, int resultCode, Intent data) like this:

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data){
        if (requestCode == YOUR_INTENT_CODE){
            //do your stuffs here
        }
    }
    

    Standaloneplayer is an activity, and, as any activity, can be started for result, so the calling activity will receive a callback when the result is received.