iOS9 视频播放
self.videoFileURL = [NSURL URLWithString:[NSString stringWithFormat:@"file:///%@", self.vedioString]];
if (!_videoFileURL) {
return;
}
AVAsset *movieAsset = [AVURLAsset URLAssetWithURL:_videoFileURL options:nil];
self.playerItem = [AVPlayerItem playerItemWithAsset:movieAsset];
self.player = [AVPlayer playerWithPlayerItem:_playerItem];
self.playerLayer = [AVPlayerLayer playerLayerWithPlayer:_player];
_playerLayer.frame = CGRectMake(0, 0, self.vedioView.frame.size.width, self.vedioView.frame.size.height);
_playerLayer.videoGravity = AVLayerVideoGravityResizeAspect;
if (!_videoFileURL) {
return;
}
AVAsset *movieAsset = [AVURLAsset URLAssetWithURL:_videoFileURL options:nil];
self.playerItem = [AVPlayerItem playerItemWithAsset:movieAsset];
self.player = [AVPlayer playerWithPlayerItem:_playerItem];
self.playerLayer = [AVPlayerLayer playerLayerWithPlayer:_player];
_playerLayer.frame = CGRectMake(0, 0, self.vedioView.frame.size.width, self.vedioView.frame.size.height);
_playerLayer.videoGravity = AVLayerVideoGravityResizeAspect;
[self.vedioView.layer addSublayer:_playerLayer];
[_playerItem seekToTime:kCMTimeZero];
[self addNotification];
[_player play];
//在视屏播放完成添加通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(finishPlayer) name:AVPlayerItemDidPlayToEndTimeNotification object:self.player.currentItem];
升级后需要注意两个地方
1 在build Settings 搜索bitcode 设置成no
2 在info.plist里添加以下属性
程序中报错:
App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.
解决方法:
在info.plist 加入key
<key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict>
posted on 2015-12-04 17:00 taiyang2014 阅读(204) 评论(0) 编辑 收藏 举报