Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Video 我可以测试IOS4 AVPlayer seekToTime何时完成吗?_Video_Ios4_Avfoundation_Avplayer - Fatal编程技术网

Video 我可以测试IOS4 AVPlayer seekToTime何时完成吗?

Video 我可以测试IOS4 AVPlayer seekToTime何时完成吗?,video,ios4,avfoundation,avplayer,Video,Ios4,Avfoundation,Avplayer,我正在使用AVFoundation实现一个AVPlayer。我想连续循环一个视频剪辑,因此我注册了一个AVPlayerItemDidPlayToEndTimeNotification来调用此方法: - (void)player1ItemDidReachEnd:(NSNotification *)notification { dispatch_async(dispatch_get_main_queue(), ^{ [player1 seekToTime:kCMTi

我正在使用
AVFoundation
实现一个
AVPlayer
。我想连续循环一个视频剪辑,因此我注册了一个
AVPlayerItemDidPlayToEndTimeNotification
来调用此方法:

- (void)player1ItemDidReachEnd:(NSNotification *)notification
{ 
 dispatch_async(dispatch_get_main_queue(),
       ^{
        [player1 seekToTime:kCMTimeZero]; 
        [player1 play];
       });
}

它有时会工作,但最终会停止播放,可能是因为
seekToTime
的异步完成。如何使此代码防弹?

我现在已通过将AVPlayer的AVPlayerActionAtItemEnd属性设置为AVPlayerActionAtItemEndNone来修复此问题-默认设置为AVPlayerActionAtItemEndPause。AVPlayer不再在剪辑结束时暂停,因此不必重新开始播放。还发现没有必要将seekToTime分派到主队列。

在Controller.h add中

AVPlayer *myplayer;
在Controller.m中添加

#import <CoreMedia/CoreMedia.h>

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(playerItemDidReachEnd:)
                                             name:AVPlayerItemDidPlayToEndTimeNotification
                                           object:[myplayer currentItem]];
[myplayer play];
}

这有助于我循环视频,但您需要缓存它一些方法(用于平滑循环)

heh,一些时间停止%(播放计数为2,5,6,11时播放):(
- (void)playerItemDidReachEnd:(NSNotification *)notification {
AVPlayerItem *playerItem = [notification object];
[playerItem seekToTime:kCMTimeZero];
[myplayer play];
- (void)playLogo {
NSString *path = [[NSBundle mainBundle] pathForResource:@"logo" 
                                                 ofType:@"m4v" 
                                            inDirectory:@"../Documents"];

self.myplayerItem = [AVPlayerItem playerItemWithURL:[NSURL fileURLWithPath:path]];
self.myplayer = [AVPlayer playerWithPlayerItem:self.myplayerItem];
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(playerItemDidReachEnd:)
                                             name:AVPlayerItemDidPlayToEndTimeNotification
                                           object:[self.myplayer currentItem]];
[videoView setPlayer:self.myplayer];
[videoView setAlpha:0.5f];
[self.myplayer play]; }

- (void)playerItemDidReachEnd:(NSNotification *)notification {
[videoView setAlpha:0.0f];
[[NSNotificationCenter defaultCenter] removeObserver:self 
                                                name:AVPlayerItemDidPlayToEndTimeNotification 
                                              object:[self.myplayer currentItem]];
[self playLogo];    }
player.actionAtItemEnd = AVPlayerActionAtItemEndNone; 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification object:[player currentItem]];

(void)playerItemDidReachEnd:(NSNotification *)notification {
AVPlayerItem *p = [notification object];
 [p seekToTime:kCMTimeZero];
}