我已经按照 Apple 文档中的建议创建了一个 AVPlayerView: https ://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/02_Playback.html
所以我将该 UIView 子类添加为我的 UIViewController 的子视图。
看起来不错,视频播放效果很好。但是,当我将视图最小化到一个小窗口时,视频不会随之调整大小。没关系,当我使用 MPMoviePlayerViewController 时,但出于几个原因我需要使用 AVPlayer [静音音频、同时播放多个视频等]。
这是我的 AVPlayerView 实现:
@implementation VideoView {
}
+ (Class)layerClass {
return [AVPlayerLayer class];
}
- (AVPlayer*)player {
return [(AVPlayerLayer *)[self layer] player];
}
- (void)setPlayer:(AVPlayer *)player {
[(AVPlayerLayer *)[self layer] setPlayer:player];
}
@end
这是我创建 AVPlayer 的方法:
AVAsset *asset = [AVURLAsset URLAssetWithURL:Url options:nil];
AVPlayerItem *anItem = [AVPlayerItem playerItemWithAsset:asset];
player_vc = [AVPlayer playerWithPlayerItem:anItem];
player_vc.actionAtItemEnd = AVPlayerActionAtItemEndNone;
player_layer = [[VideoView alloc] initWithFrame:self.view.bounds];
[self.view addSubview: player_layer];
[player_layer setPlayer:player_vc];
这是我用于更改父视图框架的代码:
-(void) minimize {
[UIView animateWithDuration:2.0
animations:^{
self.view.frame = resizeFrame;
} completion:(void (^)(BOOL)) ^{
self.minimized = true;
}
似乎一旦使用特定框架创建,我就无法将其更改为其他任何内容。
你能告诉我如何用我的视图控制器的视图调整 AVPlayer 层的大小吗?
谢谢