2012-03-28 59 views
0

我使用这个方法来播放视频使用AVPlayer:AVPlayer流状态

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

     [audioPlayer play]; 

我寻找一种方式来获得通知的每次在流过程中(像11%,10%,25% ,50%,60%......),我可以从AVPlayer得到这样的东西吗?

回答

1

看看文档,则需要实现这个方法:

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

一个例子:

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

为了让你可以做视频的总时间:

mPlayer.currentItem.duration 

以及您可以从项目中获取currentTime:

mPlayer.currentItem.currentTime 

编辑

看看CurrentItem reference

你可能需要一些像方法:

+0

loadedTimeRanges OK,这是播放过程中的时间,但什么我寻找的是从播放中快速下载的过程。 – MTA 2012-03-28 16:22:18

+0

好吧,我编辑答案,你可以得到有关该项目的信息。你可以从已经加载的数组中获得数组,等等。 – ggrana 2012-03-28 16:29:11