I need to play youtube video lists in an iphone app. I did a quick research but still could not find the answer. Most of the answers out there are about playing a single youtube video in iOS by embedding a youtube url in a HTML page and load it in a UIWebview. But it doesn't seem to be the way for playing a list. But I guess it's possible because there are apps that can do that.
Update: I managed to play a list in a UIWebView with iframe method, but it not what i set out to do. I need to play the video not in a full screen mode. Is there anyway to do so?
Thanks
Using UIWebView's internal MPMoviePlayerController, it may be possible to load the videos one by one by storing their URLs in an array and incrementing the array's object position when the finish event is sent internally by the iFrame's javascript. iFrame methods are documented here, and a way to inject a webview with javascript is shown here.
As for non-inline video playing (only fullscreen), set allowsInlineMediaPlayback to NO on the UIWebView.
Related
I want to play youtube url in UIWebview or MPMoviewviewcontroller.but the restriction is user should not control the playing video.could any one help ?
If you want finer control over youtube videos, theres a library (not written by me) called XCDYoutubeKit. Search for that and look at incorporating it into your app - theres a class in there that is based on MPMoviePlayerController, that allows the playing of youtube videos from their youtube id (I use it, its good). This also means you get a normal player, so you can pause, scrub through, etc.
I am using "YTPlayerView" to play video in iOS. When I am using this in iPhone it automatically play video in full screen but when I am using same thing in the iPad it does not switch to full screen. I also tried the below parameters but no success.
NSDictionary *playerVars = #{ #"playsinline" : #0 };
[self.playerView loadWithVideoId:videoIDURL playerVars:playerVars];
We have developed a very video intensive app for both iPhone and iPad in the past, and actually had the opposite problem - we wanted to use the YTPlayerView for displaying videos inline (non-fullscreen) on both devices, but weren't able to get it done on the iPhone. We ended up using XCDYouTubeVideoPlayerViewController, which seemed to have resolved most of our issues. This is not really the recommended way to approach this, since it pretty much breaks YouTube's terms of use (it parses the html page, finds the .mp4 url, and plays it in MPMoviePlayer, which gives all all of the flexibility you need for full screen, loading times and other notifications.
Throughout the process of trying to find a way to work with YTPlayerView, I contacted engineers form Google who work on the YouTube helper framework, and they recommended to work directly with the iframe player API, which lets you customize the controls and receive events about the video. This means you'll have to use your own web view instead of the YouTube helper. The communication between the JavaScript and the Objective-C parts can be tricky (and that's what the helper library actually tries to save from the developer), but it will give you more flexibility.
This can also help with working with UIWebView to display YouTube videos: Playing YouTube Videos in a WebView Inline.
I know it's not exactly what you asked, but I hope it can help lead you in the right direction. I've had a lot of issues working with YouTube videos on iOS, so I know how frustrating it can be. Good Luck!
I'm building an article reading app for iphone.I'm parsing JSON content of article in uiwebview.
Some of the articles contains videos,But it does not display in the uiwebview.
JSON format for video is
<iframe src=\"\/\/www.youtube.com\/embed\/hdstrm\" height=\"360\" width=\"640\" allowfullscreen=\"\" frameborder=\"0\">
The uiwebview display empty space at the place of video frame
here is screen shot of uiwebview:
Displaying YouTube videos on iOS requires special treatment and is much less straight forward than you would expect (or hope). You can either display the entire YouTube page and let the user take it from there (or try to programmatically simulate a press on the play button), or you can "steal" the MP4 and play it using the media player.
The second option is better because it allows you to control the UI around the video and doesn't force you to display the entire YouTube page. However, it's important to stress that it requires quite a bit of work and is frowned upon by YouTube. In fact, they change the HTML structure of their pages every 2-3 months so that these mechanisms will break, and you won't be able to access the MP4 file directly without changing your code.
For more information on how to access the media file directly and play it, check out https://github.com/larcus94/LBYouTubeView
I've tried tens of different ways to play a video from YouTube or a server and not have it go into fullscreen. I know it's possible because the YouTube app allows for this to happen but can't seem to figure out how to do it. Please advise!
Check out this answer:
Can I play a youtube video in a UIWebView inline (not fullscreen)?
This solution is iOS 6 & 7 compatible, it involves setting UIWebView's allowsInlinePlayback and setting YouTube's iFrame webkit-playsinline value.
I was wondering how are apps like McTube (https://itunes.apple.com/us/app/mctube-for-youtube/id559618284?mt=8) playing youtube videos. It looks like a custom MPMoviePlayerController but is that allowed?
BTW I need autoplay which I couldn't achieve with UIWebView, that's why i was wondering.
Some YouTube videos can be played back in a MPMoviePlayerController - some cannot. When you query a video through the YouTube Data API (link here) you'll get back all the content types available for a particular videos, including the Flash player, 3GPP, MP4 (if available), etc. You can use these URLs to load up a MPMoviePlayerController.
This is perfectly fine, but as I've said - not all videos are available to embed this way. Some videos (mainly ones that require adverts to be displayed) can't be put into native controllers.