获取YouTube直播活动的当前持续时间 [英] Get current duration of YouTube Live Event

查看:139
本文介绍了获取YouTube直播活动的当前持续时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当直播到YouTube时,是否可以获取记录的流的当前时间?我希望能够在整个实时流中的某些点发送API请求,以获取流的当前分钟/秒.我试图达到的最终结果是能够记录一个重点列表.本质上,用户按下一个按钮,它将获得该时刻的流的当前时间,然后用户可以为当时发生的事情添加注释.通过阅读所有文档,我找不到找到记录流的当前时间的方法.

Is there a way to get the current time of a the recorded stream when broadcasting to YouTube live? I want to be able to send an API request at certain points throughout a live stream to get the current minute/second of the stream. The end result I am trying to achieve is to be able to log a list of highlights. Essentially, a user presses a button and it gets the current time of the stream at that moment, then the user can add a note for what happened at that time. From reading all the docs though, I cannot find a way to get the current time of the recorded stream.

推荐答案

看起来您可以使用iFrame API的getDuration()方法来做到这一点.

Looks like you can do this with the iFrame API's getDuration() method.

https://developers.google.com/youtube/iframe_api_reference#getDuration

查看直播活动的特别说明:

Check out the special note for live events:

如果当前正在播放的视频是直播事件,则getDuration()函数将返回自直播视频流开始以来经过的时间.具体来说,这是视频流式传输而没有重置或中断的时间.另外,此持续时间通常比实际事件时间长,因为流式传输可能在事件开始时间之前开始.

If the currently playing video is a live event, the getDuration() function will return the elapsed time since the live video stream began. Specifically, this is the amount of time that the video has streamed without being reset or interrupted. In addition, this duration is commonly longer than the actual event time since streaming may begin before the event's start time.

您没有指定语言,所以我将以两种不同的语言发布代码示例.两者都使用iFrame API.

You didn't specify a language, so I'll post code examples in two different languages. Both utilize the iFrame API.

JavaScript:

JavaScript:

window.onYouTubePlayerReady = function(playerId) {
    window.ytplayer = document.getElementById("ytPlayer");
    console.log(window.ytplayer.getDuration());
}

Objective-C(使用YouTube的 youtube-ios-player-helper 类)

Objective-C (using YouTube's youtube-ios-player-helper class)

@property (weak, nonatomic) IBOutlet YTPlayerView *playerView;

// ...

- (void)viewDidLoad {
    [super viewDidLoad];
    [[self.playerView loadWithVideoId:@"iGTIK_8ydoI"] // live at the time answer was posted
}

// ...

- (void)getDurationOfPlayingVideo {

    NSLog(@"duration: %d", [self.playerView duration]);
}

就像我的个人测试中的免责声明一样:Live Streaming API具有非凡的性格和不稳定,而且我发现某些Live Events返回的持续时间为0.

Just as a disclaimer from my personal testing: the Live Streaming API is extraordinary temperamental and unstable, and I've found that some Live Events return a duration of 0.

这篇关于获取YouTube直播活动的当前持续时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆