I found a method to play YouTube video on MPMoviePlayerController. For this simply need a right url. That url may be obtained after playing YouTube video in iframe. My UIWebView uses
this html:
<html>
<head>
</head>
<body style="margin:0">
<iframe class="youtube-player" type="text/html" width="280"
height="200" src="http://www.youtube.com/embed/VJRKaQ52ImE"
frameborder="0">
</iframe>
</body>
So after click on play in video rect, we can see msg in console like this:
YT_Player[1520:207] setting movie path: http://v12.lscache4.c.youtube.com/videoplayback?sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Cratebypass%2Coc%3AU0hQR1NLVl9FSkNOMF9LRVpB&fexp=913518%2C904531%2C910211&itag=18&ip=0.0.0.0&signature=93772DDEDFE678D8EA1A2E4669B5634BD6D4E81E.58DEF5203DEF07FB75F762D6C9C39536C84DE59C&sver=3&ratebypass=yes&expire=1312308000&key=yt1&ipbits=0&id=54944a690e762261
So here the question is - how get YT_Player object or how to generate "right" url?
There is no official API to get the "right" url, and likely there never will be. See the following link on the bottom.
http://groups.google.com/group/youtube-api-gdata/browse_thread/thread/394c41dda8b4745a
Note that your method based on UIWebView does not play the movie in MPMoviePlayerController, but rather in a custom class called YTMoviePlayer. You can confirm it by playing a movie and then dumping the subview hierarchy starting at [[UIApplication sharedApplication] keyWindow].
For me this library did work perfectly!
https://github.com/hellozimi/HCYoutubeParser
Related
I have some youtube videos on my site. They works fine on desktop(and also when i resize the desktop browser screen to mobile screen size). But when i try to view those videos on mobile, the youtube app opens and the videos are played in the app and not on the website. I want the video to be played on the site itself and not in an app. Is there any solution for this?
HTML:
<embed src="http://www.youtube.com/v/xyz&hl=en_GB&fs=1?rel=0&border=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="100%" height="370"></embed>
You should switch to using iframe instead of embed. See Youtube iFrame Player API.
The IFrame player API lets you embed a YouTube video player on your website and control the player using JavaScript. Unlike the Flash and JavaScript player APIs, which both involve embedding a Flash object on your web page, the IFrame API posts content to an <iframe> tag on your page
Here's an example on how to use iframe:
<iframe title="YouTube" class="youtube-player" type="text/html" width="640" height="390" src=YOUTUBE_VIDEO frameborder="0" allowFullScreen></iframe>
I was wondering if it is possible to autoplay an embedded YouTube video AND also have the video start at a certain point?
Any help is appreciated.
You can just add the & to place another command in the embed script. The ? starts the first command, the & adds another. The Start command is in seconds: 1min10sec=70secs. Then just top it off with an autoplay=1 to automatically start playing.
<iframe src="https://www.youtube.com/embed/acktYyOGG6w?start=29&autoplay=1" width="1" height="1" src="" frameborder="0" allowfullscreen></iframe>
I ran into the same issue for deploying music for my church's website. The width and height were only to make it a pixel in size so the video won't show while it plays.
You see another example when you look at the playlist links.
https://www.youtube.com/watch?v=of9C-8azVh8&index=4&list=PLBjhJqE72NDQPMNhB0peXyjDQNVxSext-
My iOS application uses youtube iframe player on UIWebView to play any clip with inline mode. The following code is HTML code used.
<html>
<head>
<style type="text/css">body {background-color: transparent;color: white;}</style>
</head>
<body style="margin:0">
<iframe src="http://www.youtube.com/embed/e2w8z6mI47U?playsinline=1&rel=0&showinfo=0" width="320" height="240" frameborder="0" allowfullscreen></iframe>
</body>
</html>
Then, it is passed to loadHTMLString method.
That code had worked well until a recent date. But, I recently noticed that every clips I used aren't played normally. the standby view and play button is shown but, although I pushed the play button, it didn't play well. black screen was only shown.
I haven't found anything to solve the problem. Are there any changes of Youtube Iframe player or points I missed?
I ended up solving the problem by calling [videoView setMediaPlaybackRequiresUserAction:NO].
I don't exactly know why the method could save me. At a guess, there was a change dealing with the request for playing at youtube. I could find the following changes on youtube developer site.
January 28, 2014
The playsinline parameter controls whether videos play inline or
fullscreen in an HTML5 player on iOS. Setting the value to 1 causes
inline playback.
The Selecting content to play section has been updated to explain how
to find YouTube video IDs and playlist IDs using the YouTube Data API
(v3) rather than the older API version.
The controls parameter's definition has been updated to reflect the
fact that the parameter value only affects the time that the Flash
player actually loads in IFrame embeds. In addition, for IFrame
embeds, the parameter value also determines when the controls display
in the player. If you set the parameter's value to 2, then the
controls display and the Flash player loads after the user initiates
the video playback.
I guess that one of above changes may need extra informations which are passed from a client to youtube server for playing normally.
UPDATE:
Today, I identified that it works well without my solution. It seems that the problem was fixed lately.
My requirement is I do not want to show the video playing in full screen.
For that initially, I choose the MPMoviePlayerController. By using this static videos i.e, which is in our app are playing well but the YouTube videos i.e., contains URL are not playing, instead of that it shows blank screen.
I tried in these ways:- http://pastie.org/8484597 You may think that all the ways are same.. But I tried all the ways as I googled I got these are all the ways.
Later, I moved to UIWebView. Yes, it is absolutely good.. it is playing my videos with No Doubt. Here I am extracting the youtube id and playing. But here, I do not want to play the video in full view. But when I want to play the video we have to click on the UIWebView then instantly it is showing full screen with video playing. But, I want to play with in the web view only.
I followed this link but same problem.. Display video inside the Uiwebview not in device full screen
I tried in these ways.. http://pastie.org/8484621
(I used LBYouTubeExtractor also. it plays good but it is not playing all the videos. For some videos it throws _itemFailedToPlayToEnd error).
Please guide me how to do in UIWebView?.
Wrap the video within a html file and remember to add webkit-playsinline and change the webview attribute webview.allowsInlineMediaPlayback =YES; Then load the html file with the webview. This works for me.
The html file is like
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<video
webkit-playsinline
src="prog_index.m3u8"
height="200" width="200"
type="video/m3u8"
>
</video>
</body>
</html>
Cheers!
I'm trying to launch a webview that will play a youtube video full screen and landscape.
Most of the other posts on this are buggy and clunky, is there a simple and clean way I can implement this or do I have to use something like MPMoviePlayerController to get this effect?
Thanks!
The best way to display videos in UIWebViews are HTML5 video tags. YouTube uses iframes to embed their HTML5 videos:
<iframe
class="youtube-player" type="text/html" width="640" height="385"
src="http://www.youtube.com/embed/VIDEO_ID" frameborder="0">
</iframe>
I don't have real experience in the forced orientation issue, so I skip this part.