美文网首页
ios 9以上系统播放视频

ios 9以上系统播放视频

作者: jfzhang | 来源:发表于2018-02-07 13:54 被阅读0次

    AVPlayerItem *avPlayerItem;

    AVPlayer                    *avPlayer;

    AVPlayerLayer              *avPlayerLayer;

    NSString *file = [[NSBundle mainBundle] pathForResource:fileName ofType:@"mp4"];

     if (file == nil)

    {

      [self moviePlayFinish];

     return;

    }

        NSURL *url = [NSURL fileURLWithPath:file];

        avPlayerItem = [AVPlayerItem playerItemWithURL:url];

        avPlayer = [AVPlayer playerWithPlayerItem:avPlayerItem];

        avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:avPlayer];

        avPlayerLayer.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);

        avPlayerLayer.videoGravity = AVLayerVideoGravityResizeAspect;

        avPlayerLayer.repeatCount = 1;

        [window.layer addSublayer:avPlayerLayer];

        [avPlayerItem seekToTime:kCMTimeZero];

        [avPlayer play];

        //调用

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayFinish) name:AVPlayerItemDidPlayToEndTimeNotification object:avPlayerItem];

    相关文章

      网友评论

          本文标题:ios 9以上系统播放视频

          本文链接:https://www.haomeiwen.com/subject/szgozxtx.html