2015-08-25 49 views
1

我們希望創建一個3-4秒鐘的短片,就像他們在Apple Tips應用中一樣,您會看到一些在多次重複播放的電影中使用iPhone的示例。重複3秒鐘的幫助視圖電影?

我猜他們不使用動畫(併爲它創造了許多圖像),但使用某種電影播放器​​ - 問題是,什麼是最好的玩家使用 - 因此這看起來像一個gif播放器工具欄(播放/停止/等)。

謝謝。

回答

1

使用AVPlayer連續播放視頻,它會看起來像一個GIF持續播放。

-(void)startPlaybackForItemWithURL{ 
    // First create an AVPlayerItem 
    // Subscribe to the AVPlayerItem's DidPlayToEndTime notification. 
    NSString*thePath=[[NSBundle mainBundle] pathForResource:@"vegas" ofType:@"mov"]; 
    NSURL*theurl=[NSURL fileURLWithPath:thePath]; 
    AVPlayerItem* playerItem = [AVPlayerItem playerItemWithURL:theurl]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(itemDidFinishPlaying:) name:AVPlayerItemDidPlayToEndTimeNotification object:playerItem]; 

    player = [[AVPlayer alloc] initWithPlayerItem:playerItem]; 

    AVPlayerLayer *layer = [AVPlayerLayer layer]; 

    [layer setPlayer:player]; 
    [layer setFrame:CGRectMake(0, 0, 443, 239)]; 
    [layer setBackgroundColor:[UIColor clearColor].CGColor]; 
    [layer setVideoGravity:AVLayerVideoGravityResizeAspectFill]; 

    [viewVideo.layer addSublayer:layer]; 

    [player play]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(itemDidFinishPlaying:) name:AVPlayerItemDidPlayToEndTimeNotification object:player]; 
}