博客> iOS 引导页视频制作 Welcome Video
iOS 引导页视频制作 Welcome Video
2小时前 评论:0 阅读:372 taito
ios Welcome Video 引导页 开机画面

相信大家看过不少 App 用视频做引导页了。如果想做引导页视频,推荐性能更好的做法是引用 AVFoundation 库。直接看下代码片段:

...
@property (nonatomic) AVPlayer *player;
...

- (void)play
{
   NSString *filePath = [[NSBundle mainBundle] pathForResource:@"intro_video" ofType:@"mp4"];

    AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:[NSURL fileURLWithPath:filePath]];

    self.player = [AVPlayer playerWithPlayerItem:playerItem];
    self.player.volume = 1.0; // 控制音量大小

    AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.player];
    playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
    playerLayer.frame = self.view.layer.bounds; // 放置的视图大小
    [self.view.layer addSublayer:playerLayer];  // 添加在 layer 层上

    [self.player play];

    // 监听播放通知,让它循环播放
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayDidEnd:)
                                                 name:AVPlayerItemDidPlayToEndTimeNotification
                                               object:self.player.currentItem];  
}

- (void)moviePlayDidEnd:(NSNotification*)notification{
    AVPlayerItem *item = [notification object];
    [item seekToTime:kCMTimeZero];
    [self.player play];
}

想省时间的朋友,可以直接看我做的 Demo : ZWIntroductionViewController

也可以直接集成在引导页中。

收藏
0
sina weixin mail 回到顶部