問題描述:
在Android中,視頻可以正常在H5頁面局部播放。
iOS中則自動切換至全屏模式,需要禁止視頻自動全屏播放。
解決方法:
H5端:
iOS10以上H5視頻不自動全屏播放識別 playsinline這個屬性
iOS10以下H5視頻不自動全屏播放識別 webkit-playsinline這個屬性
x5-video-player-type='h5' x5-video-player-fullscreen='true' playsinline webkit-playsinline
注意::在客戶端設(shè)置了相關(guān)屬性之后,網(wǎng)頁就可以通過
playsinline='true' webkit-playsinline='true'來控制視頻在網(wǎng)頁內(nèi)播放
playsinline='false' webkit-playsinline='false'來控制視頻全屏播放
iOS 端實現(xiàn)代碼:
UIWebView
webView.allowsInlineMediaPlayback = YES;
WKWebView
WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
configuration.allowsInlineMediaPlayback = YES;
_webview = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight - 88) configuration:configuration];
注意::這里需要將屬性設(shè)置在初始化的
WKWebViewConfiguration對象上,因為_webview. configuration為原始對象拷貝的原因,所以通過以下方式設(shè)置相應(yīng)屬性并不會生效:_webview.configuration.allowsInlineMediaPlayback = YES; /*! @abstract A Boolean value indicating whether HTML5 videos play inline (YES) or use the native full-screen controller (NO). @discussion The default value is NO. */ @property (nonatomic) BOOL allowsInlineMediaPlayback;
參考:
- http://www.itdecent.cn/p/69ab92267343
- https://blog.csdn.net/qq_40190624/article/details/100524387
- https://developer.apple.com/documentation/webkit/wkwebviewconfiguration/1614793-allowsinlinemediaplayback
- https://stackoverflow.com/questions/6039909/html5-full-screen-video
- http://www.itdecent.cn/p/f313bd152b74