xcode AVPlayerseektoTime iPhone
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10615038/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
AVPlayer seektoTime iPhone
提问by Omer Waqas Khan
I have used seekToTime in my application and its working properly. But I want to have some more information about it. Which is, if I have a streaming video file of 1 minute now I want to play it from second 15th to second 45 (first 15 seconds and the last 15 seconds will not play).
我在我的应用程序中使用了 seekToTime 并且它工作正常。但我想了解更多有关它的信息。也就是说,如果我现在有一个 1 分钟的流媒体视频文件,我想从 15 秒到 45 秒播放它(前 15 秒和最后 15 秒不会播放)。
How can I do it?
我该怎么做?
I know that by use of seekToTime I can play a video from 15th second but how to stop it at 45th second and also get noticed by the method that the video has played for the specified time period?
我知道通过使用 seekToTime 我可以从第 15 秒开始播放视频,但是如何在第 45 秒停止播放并通过视频在指定时间段内播放的方法引起注意?
CMTime timer = CMTimeMake(15, 1);
[player seekToTime:timer];
The above code takes me to the 15th second of the streaming file but how to stop it on 45th second and get notified too?
上面的代码将我带到流文件的第 15 秒,但如何在第 45 秒停止它并获得通知?
I have searched a lot but couldn't get any info.
我已经搜索了很多,但无法获得任何信息。
Thanks
谢谢
EDIT:
编辑:
As @codeghost suggested, simply use forwardPlaybackEndTime
.
正如@codeghost 所建议的,只需使用forwardPlaybackEndTime
.
You can simply use:
您可以简单地使用:
yourAVPlayerItem.forwardPlaybackEndTime = CMTimeMake(10, 1);
Here 10 is the time till the AVPlayerItem will play.
这里 10 是播放 AVPlayerItem 的时间。
回答by codeghost
Set the forwardPlaybackEndTime
property on your AVPlayerItem.
forwardPlaybackEndTime
在您的 AVPlayerItem 上设置属性。
回答by MTA
I don't know if there is something build-in for this in AVPlayer
, but what i would do is build an function and call it with :
我不知道 in 中是否有内置的东西AVPlayer
,但我要做的是构建一个函数并使用以下命令调用它:
[self performSelector:@selector(stopPlaying) withObject:nil afterDelay:45];
-(void)stopPlaying{
[player pause];
}
this will stop playing after 45 seconds,and of course you can put instead 45 any number of seconds that you want.
这将在 45 秒后停止播放,当然,您可以根据需要输入 45 秒。
回答by Ron
You can use [AVPlayer addPeriodicTimeObserverForInterval:queue:usingBlock:]
for that purpose.
您可以[AVPlayer addPeriodicTimeObserverForInterval:queue:usingBlock:]
为此目的使用。
Get the AVPlayer.currentTime
periodically, and call pause or stop on the exact time.
AVPlayer.currentTime
定期获取,并在确切时间调用暂停或停止。