【发布时间】:2017-11-08 19:49:08
【问题描述】:
我有一个带有透明背景的“.mov”视频,可以在我的视图上添加效果,但是当我尝试播放它时,视频会加载 n 次播放,但我得到一个空白屏幕,这是我的代码:
@property (nonatomic) AVPlayer *avPlayer;
@property (nonatomic) AVPlayerViewController* avPlayerView;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSBundle* bundle = [NSBundle mainBundle];
NSString* path = [bundle pathForResource:@"Spit" ofType:@"mov"];
NSURL *fileURL = [NSURL fileURLWithPath:path];
AVAsset *asset = [AVURLAsset URLAssetWithURL:fileURL options:nil];
AVPlayerItem *anItem = [AVPlayerItem playerItemWithAsset:asset];
_avPlayer = [AVPlayer playerWithPlayerItem:anItem];
[AVPlayer addObserver:self forKeyPath:@"status" options:0 context:nil];
_avPlayerView = [[AVPlayerViewController alloc] init];
_avPlayerView.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
_avPlayerView.player = _avPlayer;
[_avPlayerView view].backgroundColor = [UIColor clearColor];
[_avPlayerView view].alpha = 0.5;//or any value you think is right
[self.view addSubview:_avPlayerView.view];
}
如果有人有想法,任何帮助将不胜感激,在此先感谢。
【问题讨论】:
标签: ios objective-c avplayer