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.
Related
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?
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.
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/"]];
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.
I have made a simple test page that fails with chrome, but works with IE.
It is at:
http://www.rateforsuccess.com/test2.aspx
If you use IE, you will see that the video plays for about a second, and then you can do a seek, (with the SEEK button) and it will seek 100 seconds into the video, and play for about 7 seconds. You will see and hear a woman talking.
But in chrome, this fails multiple ways. Sometimes clicking the SEEK button does not work the first time but works the second time. Sometimes the clip will play, but without any visuals - you just hear the audio.
Its a simple page, so I do not understand this.
There is a another odd thing, sometimes if you clear the cache and then access the page, you get the error, but if you don't clear the cache, eventually it works (sometimes).
Any help is appreciated.