由 UIView 类子类实现的 AVPlayer 模块
AVPlayerView 可通过 CocoaPods 使用。要安装它,只需将以下行添加到您的 Podfile
pod "AVPlayerView"
然后运行
$ pod install
#import <AVPlayerView/CrAVPlayerView.h>
AVPlayerView *avPlayerView = [[AVPlayerView alloc] initWithFrame:CGRectMake(0, 0, 300, 200)];
NSString *path = [[NSBundle mainBundle] pathForResource:@"short" ofType:@"mp4"];
[avPlayerView playerWithContentURL:[NSURL fileURLWithPath:path]];
avPlayerView.autoplay = YES;
avPlayerView.loop = YES;
avPlayerView.dimmedEffect = YES;
avPlayerView.pauseWhenDisappear = YES; //default: true
avPlayerView.showControl = NO; //default: true
self.backgroundColorForFullSize = [UIColor blackColor]; //default: black
[avPlayerView setTapCallBack:^(AVPlayerView *playerView) {
if (playerView.isFullSize) {
[playerView normalSizeMode];
} else {
[playerView fullSizeMode];
}
}];
[self.avPlayerView setDidAppear:^(AVPlayerView *playerView) {
//do somthing;
}];
[self.avPlayerView setDidDisappear:^(AVPlayerView *playerView) {
//do somthing;
}];
[self.avPlayerView setFailure:^(AVPlayerView *playerView) {
//do somthing;
}];
NSString *path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"mp4"];
[self.avPlayerView playerWithContentURL:[NSURL fileURLWithPath:path]];
self.pauseWhenDisappear = YES; //default: true
self.avPlayerView.showControl = YES; //default: true
self.backgroundColorForFullSize = [UIColor blackColor]; //default: black
[self.avPlayerView setTapCallBack:^(AVPlayerView *playerView) {
//do something;
}];
[self.avPlayerView setDidAppear:^(AVPlayerView *playerView) {
//do something;
}];
[self.avPlayerView setDidDisappear:^(AVPlayerView *playerView) {
//do something;
}];
[self.avPlayerView setFailure:^(AVPlayerView *playerView) {
//do somthing;
}];
skswhwo, [email protected]
AVPlayerView 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。