Youtube embedded videos Done button not working in iOS 10 - ios

I am passing an URL link of youtube to a WebView. The video plays in full screen due to which the navigation bar hides, in order to bring the navigation bar back we have to click the "Done" button in the upper left corner. My app works fine with iOS 9 devices but in the latest update i.e iOS 10 this is not working. The done button does not respond or else the screen goes blank and video continues to play. Any help will be highly appreciated.
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:#""]];
[webView loadRequest:request];
This is how i pass the URL

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 Black Screen When Navigating To/From Another Section

I have a tabbed application. Each tab loads a table view controller inside a navigation controller to maintain the upper navigation bar.
The table view controller presents a list of videos. Upon clicking a table cell, the user is presented with a MPMoviePlayerViewController which loads the requested video using the following code:
VideoViewController * playerController = [[VideoViewController alloc] initWithContentURL:url];
[self.navigationController pushViewController:playerController animated:YES];
[playerController.moviePlayer prepareToPlay];
[playerController.moviePlayer play];
UIBarButtonItem *mailButton = [[UIBarButtonItem alloc] initWithTitle:#"Email Link" style:UIBarButtonItemStylePlain target:self action:#selector(openMailBasket:)];
playerController.navigationItem.rightBarButtonItem = mailButton;
Note: VideoViewController is a subclass of MPMoviePlayerViewController.
This works great. However, if I click a tab at the bottom to navigate to another section, then go back to the Videos section, it misbehaves.
In IOS 5, the video starts back at the beginning. This is fine.
In IOS 6, I get a blank video screen that says "Loading..." and never loads.
In IOS 7, I am given a black video player with a total time of 0:00.
Its like the video has been 'unloaded' in IOS 6 and IOS 7. However, if I execute this in viewWillAppear:
NSString *vidURL = [self.moviePlayer.contentURL absoluteString];
NSLog(#"URL: %#",vidURL);
The URL is valid.
Note: I must use MPMoviePlayerViewController instead of MPMoviePlayerController because I need the 'Email Link' button to appear at the top.
Do I need to do anything special to get MPMoviePlayerViewController to maintain the video's state when I navigate elsewhere? Is ARC deallocating my video, and if so, why does it work in IOS 5, and what can I do about it?
Well, apparently typing it out on here led me to find the solution, so I'll lay it out.
I got to thinking about why it was working on IOS 5 and not 6 or 7. It seemed to me that ARC was probably autoreleasing my video data, and I needed a way to tell IOS that I want to bring the movie back.
All I needed to do was add:
-(void)viewWillAppear:(BOOL)animated
{
[self.moviePlayer prepareToPlay];
}
to my VideoViewController class.

Video Embedded in HTML5 won't play in UIWebView

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.

How to open youtube video on UIButton action in iOS?

I want open youtube video on UIButton action and after finishing youtube video. The control come to application by clicking DONE button, How we can achieve this?
1: Create a UIWebView with frame
2: Add it as a SuView
3: loadRequest using URL
[myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.youtube.com]]];

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