I am getting an error in Console when app exits from fullscreen and screen UI slides to top.
Error:
-[AVPlayerViewController exitFullScreenAnimated:completionHandler:] failed with error View needs to be loaded before you can call -[AVPlayerViewController (0x1028b5000) exitFullScreenAnimated:completionHandler:]!
App plays youtube videos in embedded HTML in UIWebView.
Code:
var webView = UIWebView(frame: self.view.frame)
webView.allowsInlineMediaPlayback = true
webView.mediaPlaybackRequiresUserAction = false
embededHTML = "<html><body style='margin:0px;padding:0px;'><script type='text/javascript' src='http://www.youtube.com/iframe_api'></script><script type='text/javascript'>function onYouTubeIframeAPIReady(){ytplayer=new YT.Player('playerId',{events:{onReady:onPlayerReady}})}function onPlayerReady(a){a.target.playVideo();}</script><iframe id='playerId' type='text/html' width='\(self.view.frame.size.width)' height=\(frameHeight) src='http://www.youtube.com/embed/\(youtube_code)?enablejsapi=1&rel=0&playsinline=1&autoplay=1&showinfo=0&modestbranding=0' frameborder='0'></body></html>"
@IBAction func playVideo(_ sender: Any) {
if let webView = webView {
self.view.bringSubview(toFront: webView)
webView.scrollView.isScrollEnabled = false;
webView.scrollView.bounces = false;
// Load your webView with the HTML we just set up
webView.loadHTMLString(embededHTML, baseURL: Bundle.main.bundleURL)
}
}
Any help highly appreciated. Thanks.
Try replacing UIWebView
with WebKit's WKWebView
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With