我使用AVPlayer从URL播放视频。下面我使用的代码:
@implementation VideoPlayerController {
IBOutlet UIWebView* webView;
}
-(void)viewDidLoad {
[super viewDidLoad];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
NSString* urlString = [NSString stringWithFormat:@"%@", self.videoUrl];
NSURL *videoURL = [NSURL URLWithString:urlString];
[self startPlaybackForItemWithURL:videoURL];
}
-(void)startPlaybackForItemWithURL:(NSURL*)url {
// First create an AVPlayer
AVPlayer *player = [AVPlayer playerWithURL:url];
self.player = player;
// Begin playback
[player play];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:YES];
[[UIDevice currentDevice] setValue:
[NSNumber numberWithInteger: UIInterfaceOrientationPortrait]
forKey:@"orientation"];
[self.player pause];
}
@end
因此,在iOS 12设备上,视频加载时间很长,但是在播放之后……但是在某些设备上(在iOS 11.4,iPhone 7 32 Gb上)则存在一些错误:
Task <7813A625-BBCF-4486-BC48-D6B066129F41>.<2> finished with error - code: -999
Task <37ED66A3-0404-414D-969E-CB5E118BDE4B>.<1> finished with error - code: -999
TIC Read Status [40:0x0]: 1:57
Task <37ED66A3-0404-414D-969E-CB5E118BDE4B>.<1> HTTP load failed (error code: 12 [1:12])
我必须使用媒体服务器播放视频的示例为here
我需要代码帮助,或者视频播放不好。
谢谢!