使用 Youtube 的 Livestreaming API 直播到其他人的频道

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

我尝试了 youtube 的 watchme 应用程序进行直播,我相当理解代码。在我的用例中,用户需要能够直播到另一个频道。我知道这里需要 Stream 密钥,但我需要一个粗略的指导,了解我需要在代码中更改的位置。任何提示或粗略的想法也可以。我只需要抢先一步。

如果您使用 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 方法:

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

请注意,广播 ID 已发送至 StreamerActivity 以便能够完成活动 (endEvent),而您将无法使用外部直播来完成此活动。

event.getIngestionAddress() 是流密钥 url 例如:

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

因此您可以创建如下方法:

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