Search code examples
youtube-apiyoutube-data-apiandroid-youtube-apiyoutube-livestreaming-api

Live stream using Youtube's Livestreaming API to someone else's channel


I tried youtube's watchme app for live streaming and I understand the code fairly. In my use case the user needs to be able to live stream to another channel. I understand there is a need of Stream key here, but I need a rough guidance on where I need to change in the code. Any hints or a rough idea would do too. I just need headstart.


Solution

  • If you are using Youtube WatchMe app for Android, it will create live events on your Youtube account. If you want the user to type a Stream Key from a Live stream issued from another Youtube account you will have to create a function similar to the startStreaming method :

    public void startStreaming(EventData event) {
    
        //the event is already started on your external live stream
        //String broadcastId = event.getId();
        //new StartEventTask().execute(broadcastId);
    
        Intent intent = new Intent(getApplicationContext(),
                StreamerActivity.class);
        intent.putExtra(YouTubeApi.RTMP_URL_KEY, event.getIngestionAddress());
    
        // we don't need this since it's only used to end the live event
        intent.putExtra(YouTubeApi.BROADCAST_ID_KEY, "");
    
        startActivityForResult(intent, REQUEST_STREAMER);
    }
    

    Note that broadcast id is sent to StreamerActivity in order to be able to finish the event (endEvent) which you won't be able to do using an external live stream.

    event.getIngestionAddress() is the Stream Key url eg :

    rtmp://a.rtmp.youtube.com/live2/<Stream key>
    

    So you can create a method like the following :

    public void startStreaming(String streamKey) {
    
        String url = "rtmp://a.rtmp.youtube.com/live2/" + streamKey;
    
        Intent intent = new Intent(getApplicationContext(), StreamerActivity.class);
        intent.putExtra(YouTubeApi.RTMP_URL_KEY, url);
        intent.putExtra(YouTubeApi.BROADCAST_ID_KEY, "");
    
        startActivityForResult(intent, REQUEST_STREAMER);
    }