Youtube现在有一个实时流媒体部分,允许用户广播自己的直播会话。在“直播”部分中,有2个选项:“立即直播[Beta]”和“活动”。
Live Now是一种快速简便的方法,只需将视频编码器指向指定的RTMP Url和Stream Key即可自动启动流媒体会话。它将自动检测入媒体并开始公开播放。
事件几乎是一样的,但是使用高级设置,虽然它不会自动开始广播,你需要手动设置所有内容。
我知道Youtube API允许您检索事件的摄取URL和streamkey,因此您可以广播到该目标,但它还需要手动管理许多其他步骤(如发布流,使用流绑定广播,检查状态,开始,停止等。)。另一方面,“Live Now”会自动生成所有内容。
问题:如何从Youtube API v3中检索“Live Now”提取信息(rtmp url和streamkey)?
答案 0 :(得分:10)
默认广播可以通过livebroadcasts.list检索,其中broadcastType设置为" persistent"。
可以使用boundstreamid通过livestreams.list检索默认直播。
答案 1 :(得分:2)
你无法检索"现在直播"提取信息,因为API无法区分" Live Now"和"活动。"这两个选项作为API的顶层提供给最终用户,因此他们不必编写自己的与API接口的应用程序。
您必须手动设置liveBroadcast
和liveStream
个对象,将其与liveBroadcasts.bind
绑定,测试您的流,并使用{转换为liveStream
对象上的实时对象{3}}
答案 2 :(得分:1)
获取“Live Now”rtmp和streamkey
$broadcastsResponse = $youtube->liveBroadcasts->listLiveBroadcasts(
'id,snippet,contentDetails',
array(
'broadcastType' => 'persistent',
'mine' => 'true',
));
$boundStreamId = $broadcastsResponse['items']['0']['contentDetails']['boundStreamId'];
$streamsResponse = $youtube->liveStreams->listLiveStreams('id,snippet,cdn', array(
// 'mine' => 'true',
'id' => $boundStreamId
));
print_r($streamsResponse);
答案 3 :(得分:0)
// Keep client_id,client_secret and redirect_uri the client_secrets.json
UserCredential credential;
string BoundStreamId = string.Empty;
string StreamKey=string.Empty;
using (var stream = new FileStream("client_secrets.json", FileMode.Open,
FileAccess.Read))
{
credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets,
new[] { YouTubeService.Scope.Youtube,YouTubeService.Scope.YoutubeReadonly},
"user",
CancellationToken.None,
new FileDataStore(this.GetType().ToString())
);
}
if (credential != null)
{
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "MyApp" // your app name
});
LiveBroadcastsResource.ListRequest lbRequest = youtubeService.LiveBroadcasts.List("id,snippet,contentDetails,status");
lbRequest.BroadcastType = LiveBroadcastsResource.ListRequest.BroadcastTypeEnum.Persistent;
lbRequest.MaxResults = 10;
lbRequest.Mine = true;
var bcResponse = await lbRequest.ExecuteAsync();
IEnumerator<LiveBroadcast> iLB = bcResponse.Items.GetEnumerator();
while (iLB.MoveNext() && string.IsNullOrEmpty(liveChatId))
{
BoundStreamId = livebroadcast.ContentDetails.BoundStreamId;
}
LiveStreamsResource.ListRequest lsRequest =
youtubeService.LiveStreams.List("id,snippet,cdn,status");
lsRequest.MaxResults = 50;
lsRequest.Id = BoundStreamId;
var srResponse = await lsRequest.ExecuteAsync();
IEnumerator<LiveStream> iLS = srResponse.Items.GetEnumerator();
if (srResponse != null)
{
foreach(LiveStream lvStream in srResponse.Items)
{
StreamKey= lvStream.Cdn.IngestionInfo.StreamName);
}
}
}