1. 程式人生 > >UiWebview/UIWkwebview 視屏播放那些事

UiWebview/UIWkwebview 視屏播放那些事

1.iOS 禁止webView播放網頁視訊彈出全屏

不廢話了,直接上程式碼

    CGFloat phoneVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
    if (phoneVersion >= 10.0) {
        content = [content stringByReplacingOccurrencesOfString:@"<video" withString:@"playsinline"];
    }else {
        content = [content stringByReplacingOccurrencesOfString:@"<video"
withString:@"<video webkit-playsinline"]; }

最後別忘了設定webView的allowsInlineMediaPlayback屬性為YES
webView.allowsInlineMediaPlayback = YES;

2.全域性豎屏,只有webview播放視訊橫屏;

繼承MPMoviePlayerViewController建立控制器;

- (void)viewDidLoad {
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 
    self.view
.frame = CGRectMake(0, 0, self.view.bounds.size.height, self.view.bounds.size.width); self.view.center = CGPointMake(self.view.bounds.size.width/2, self.view.bounds.size.height/2); CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI/2); [self.view setTransform:transform]; }

呼叫:

- (void)videoPlayer
{
    NSString *file = [[NSBundle mainBundle] pathForResource:@"testMove" ofType:@"mp4"];
    NSURL *url = [NSURL fileURLWithPath:file];
    JQVideoPlayerViewController *playerViewController= [[JQVideoPlayerViewController alloc] initWithContentURL:url];
    [self presentMoviePlayerViewControllerAnimated:playerViewController];
}