Video Embedded in HTML5 won't play in UIWebView - ios

I am loading up a website that has a video embedded in the code on the 5th 'page'. This video plays just fine in the full Safari, but I'm having an issue in my app. The code for loading it is:
- (void)viewWillAppear:(BOOL)animated {
NSURL *url = [NSURL URLWithString:_entry.articleUrl];
[_webView loadRequest:[NSURLRequest requestWithURL:url]];
timer = [NSTimer scheduledTimerWithTimeInterval:(1.0/2.0) target:self selector:#selector(tick) userInfo:nil repeats:YES];
}
When I get to the page with the video, it shows up in the frame:
but when I click on the play button, the app begins messing up.
After clicking on it, the MPMoviePlayerController briefly appears, but instantly gets dismissed and it reloads the original URL, taking the user back to the first page of the issue. Any thoughts to what may be happening here, or better ways for me to code the app to make sure the video plays in the proper controller?

Have you checked the format? If not, it's possible it might be a type of file that iOS doesn't play nicely with.
If that's the case, simply drag the mp4 file into iMovie and then click on Share -> Export Movie and select one of the iPhone-compatible formats.

That website contains flash video files which are not supported over iOS.
When you play it on default iOS Safari, webpage is checking its user-agent and automatically shift your page to mobile (iOS) compatible site.
For your application, you require to use that weblink only:
Try this URL instead of current one:
http://kaiopublications.org/content//iLuminateVol1Issue2/html5/index.html
This should work in your app.

The issue ending up being that when the view disappeared it was setting it to an about:blank page. So, when the movie controller took over the view to play, it passed that line of code.

Related

UIWebView ignores mediaPlaybackRequiresUserAction on iOS 10

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?

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.

Video will not play a second time on iOS devices

I'm not sure what the problem is. I have a video that I'd like to play in a modal dialog.
I have everything set up and working fine on all devices. The only issue that I've been unable to overcome is that the video will not play a second time on iOS devices.
http://c4sandbox.com/video/index.html is a simple demonstration of the problem that I'm having. If you close the dialog (it will auto close when the video ends) then click the 'show again' link on an iOS device, then the video player is just an empty black box.
What am I missing? This happens in Safari and Chrome, but only on iOS.
EDIT: The problem appears to be with video.js because a straight html5 video tag will play the video multiple times as expected. Unfortunately, I need the flash fallback so html5 only is not an option.
I'm having a similar issue. The way I am getting around it is using the player's dispose() method to kill the instance and re-injecting the HTML for the player and re-instantiating it.
Thanks #Victor! your solution works. Since there is no example code given, here is the code I used.
//Init
videoPlayer = _V_("video_post", {
controls:true,
preload:"auto",
autoplay:true,
}, function(){
});
after you're done with the player (e.g. closes the video dialog), dispose the player
videoPlayer.dispose();
Done. hope this helps.

How to prevent my MPMoviePlayerController from getting black when back from a webView containing a YouTube Video - iOS

Here is the context :
NavigationController -> FirstViewController -> SecondViewController
FirstViewController display a MPMoviePlayerController in embedded mode, and buttons to go to SecondViewController. This MPMoviePlayerController is reading a local .m4v file.
SecondViewController display a UIWebView with web pages containing YouTube videos.
Here are the steps :
the user read the video on FirstViewController (works fine)
the user press one of the buttons to go to SecondViewController
the user press one of the youtube video, that will play in embedded mode in the webView (works fine too)
the user press the Back button in NavigationItem
The problem appear at this particular moment :
When the user come back from SecondViewController, the MPMoviePlayerController is black.
I tried using prepareToPlay on the moviePlayer in viewWillAppear and/or viewDidAppear. In both cases, I got a good result for half a sec and then the MoviePlayer view is turned to black again.
I think that when the viewDidUnload is called in the SecondViewController, something happen that put a brief access to the web embbedded MoviePlayer.
Any idea about how to solve the problem ?
Note : this only appear on a device because videos don't appear on UIWebView in simulator. I tried to reproduce it with another MPMoviePlayerController in the second view but putting a prepareToPlay in the viewDidAppear solved it...
Note 2: this problem only appear on iPad. I tried to reproduce it on iPhone but the youtube player won't play video in embedded mode on iPhone...
There should be no movie player code. Just put your video url on your web view code it shall work fine.

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.

Resources