简体   繁体   English

AVPlayer流状态

[英]AVPlayer Stream status

I am using this methods for playing video with AVPlayer: 我正在使用以下方法通过AVPlayer播放视频:

        audioPlayer = [[AVPlayer playerWithURL:[NSURL URLWithString:url]] retain];
        avPlayerLayer = [[AVPlayerLayer playerLayerWithPlayer:audioPlayer] retain];
        [avPlayerLayer setFrame:self.view.bounds];

        [audioPlayer play];

I search for a way to get notification every-time in the stream process (something like 1%,10%,25%,50%,60%......), can i get something like this from AVPlayer ?? 我正在寻找一种在流处理过程中每次都获取通知的方法(例如1%,10%,25%,50%,60%......),我可以从AVPlayer获得类似的东西吗?

Take a look at the documentation, you need to implement this method: 看一下文档,您需要实现此方法:

http://developer.apple.com/library/mac/#documentation/AVFoundation/Reference/AVPlayer_Class/Reference/Reference.html#//apple_ref/occ/instm/AVPlayer/addPeriodicTimeObserverForInterval:queue:usingBlock : http://developer.apple.com/library/mac/#documentation/AVFoundation/Reference/AVPlayer_Class/Reference/Reference.html#//apple_ref/occ/instm/AVPlayer/addPeriodicTimeObserverForInterval:queue:usingBlock

An example: 一个例子:

[mPlayer addPeriodicTimeObserverForInterval:CMTimeMake(1, 1)
         queue:NULL
         usingBlock:^(CMTime time){
             NSLog(@"%lld %d ",mPlayer.currentTime.value,mPlayer.currentTime.timescale);
         }
];

To get the total time of the video you can do: 要获取视频的总时间,您可以执行以下操作:

mPlayer.currentItem.duration

As well you can get the currentTime from the item: 您还可以从该项目获取currentTime:

mPlayer.currentItem.currentTime

Edit : 编辑

take a look at CurrentItem reference 看看CurrentItem参考

you probably want some method like: 您可能想要某种方法,例如:

loadedTimeRanges loadedTimeRanges

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM