UIWebView ignores mediaPlaybackRequiresUserAction on iOS 10 - ios

I am using a UIWebView to play a local video file. Before iOS 10, the video would load and that play triangle would be displayed on top of it and that would be it. Now it autoplays.
The video is loaded as follows:
NSURLRequest *request = [NSURLRequest requestWithURL:localVideoUrl];
[self.webView loadRequest:request];
mediaPlaybackRequiresUserAction is set to YES.
I have tried to wrap my video in HTML and then load it with loadHTMLString:baseUrl:, but even though that takes care of the autoplay problem, the web view fails to display a preview image and shows only the play triangle instead. While I could probably get this working by generating my own thumbnail from the first frame of the video and showing that as the poster and then add code to display everything in the correct place and at the right size, that would add a prohibitive amount of complexity and, frankly, the problem is not so serious to warrant that kind of work.
Calling
[webview stringByEvaluatingJavaScriptFromString: #"document.querySelector('video').pause();"
in webViewDidFinishLoad: to pause the video also has no effect.
Is there any way to force the web view to wait for the user to initiate playback in this scenario, just like it used to before iOS 10?

Related

MPMoviePlayerViewController locks up application with unusual appearance?

So, I've tried this a number of ways with the same result.
I've tested by using a YouTube MP4 URL, such as:
This
The way I do it looks pretty much like:
self.moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:videoUrlString]];
And then I play the video. If I play the video and it goes fullscreen, the whole app locks up. The video player appears, but parts of the status bar (such as the time and bars) disappear leaving only the carrier name. The volume slider is only half there, and it loads indefinitely, and ignores any further touch input until I kill the app. If I rotate the iPhone, the volume slider and the rest of the status bar reappear, but it still will not respond to touch or finish loading. Screenshot of issue.
If, instead, I pass the MPMoviePlayerViewController object to a UINavigationController with presentViewController:, the app seems to hang: until I rotate, then suddenly the video appears correctly and starts playing! However, again, all touch input is ignored and the application is essentially locked.
This is one of the strangest issues I've troubleshot.
So I tried using tools others have built. I tried XCDYouTubeKit and YKMediaKit using the Youtube ID instead of the direct link, with the exact same result. After looking at their code, they both use MPMoviePlayerViewControllers.
What's happening here? Can anyone help me figure out what's wrong?
That's surprising. Have you tried playing around with AV Foundation? It's a more modern media API than MediaPlayer.framework.
If you can target iOS 8 only, then AVPlayerViewController is a simple way to playback media via AVPlayer.

Display youtube video that contains content protected by copyright

I am making a scroll view in which there are multiple instances of UIWebView, each with a youtube video that user can tap and watch. I tried multiple approaches how to this (I mean, what to put in UIWebView), the one that worked best was from https://developers.google.com/youtube/iframe_api_reference#Loading_a_Video_Player
However, I have a video that doesn't play, instead it displays "This video contains content from SME. It is restricted from playback on certain sites" (it worked fine at first and I wasn't getting this message, no idea why it stopped working). Is there a way to make such video play in iOS app? If yes, how?
P.S.
I don't want to kick the user out of my app and send him to youtube app or safari.
I also want to be able to count how many times did user play the video, but this topic is probably big enough for a separate question.
Try loading video with this:
[_videoWebView loadHTMLString:html baseURL:[NSURL URLWithString:#"http://www.youtube.com/"]];

How can I force a video played in a UIWebView to be full screen on an iPad?

I'm playing a YouTube video using a UIWebView, like so:
self.webView.mediaPlaybackRequiresUserAction = NO;
self.webView.allowsInlineMediaPlayback = NO;
[self.webView loadHTMLString:videoEmbedCode baseURL:nil];
I want to force the video to play in full screen without the user tapping the button at the bottom right. This works fine on an iPhone (tap the player to play and it automatically enters full screen), but doesn't work on an iPad (the normal inline player is shown).
I assumed that setting allowsInlineMediaPlayback to NO would do the trick, but apparently not.
Is there a way to force HTML5 videos to play in full screen on an iPad?
If you are trying to play a youtube video in fullscreen directly, then Use a webview of size fullScreen and then handle its rotation accordingly and change the player size of Rotation too. If you need more help then i can help you with the code too for how to change the player size on rotation too.

Very weird behavior showing a Youtube video on iPad

I have an array of youtube video links, and I put them in a tableview. When the user clicks on one row a WebView is pushed in, and I point it to the video URL like this
[web loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"https://www.youtube.com/watch?v=wQXIuYVNM9Q"]]];
this was working perfectly 'till yesterday, and the result was
but since today the behavior is different! What happens is that the firs time I click on a row, the video is displayed as always. But then if I go back and click on the same video again, it doesn't appear anymore, and istead I get the following screen
This is very weird! If I choose an other video from the list the first time it loads, then from the second time it doesn't and I get the same useless screen with the video thumbnails.
Even if I uninstall the app and start it again, the video that were already clicked don't work, while the others work just once. It looks like it's a cache problem or something similar...
Please help me, this is driving me mad!
have you tried to use the embedded link from youtube as this may solve this issue.
Found a weird workaround using arc4number:
NSString *s = #"https://www.youtube.com/watch?v=DLl92XBsYmc&feature=youtube_gdata"
s = [s stringByAppendingFormat:#"%f", arc4random()];
[web loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:s]]];
so every time the address is different, and the video gets displayed.

Clearing after-image from Airplay device, using UIWebView

I send a secondary UI to AirPlay - on iOS 5.1.
On the iPad, the user may use a UIWebView to play a video, and if they have Airplay setup, the video will be sent to the AirPlay device. When the video finishes playing or if the user pauses, the UIWebView does not clear out the image from the AirPlay screen.
If I then load a different URL to the UIWebView, the AirPlay image will clear out, but only after a few seconds.
I've tried to work-around this by loading a blank page, and then reloading the original video page, but that does not seem to work. Any thoughts?
In my effort to also clear other types of content from a UIWebView, I happened to discover that the following statement will also disconnect the AirPlay video connection immediately, and thereby revealing any underlying secondary UI sent via UIScreen.
[myWebView stringByEvaluatingJavaScriptFromString:#"document.body.innerHTML = \"\";"];

Resources