How can I get the Thumbnail from Youtube URL? - iphone

NSURL *youTubeURL = [NSURL URLWithString:#"http://www.youtube.com/watch?v=HPwyVw_6vsQ&feature=youtu.be"]; // URL is a string which needs to be placed in #"" and close method call with ].
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:youTubeURL];
imageSel = [player thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame];
I am using this code for getting thumbnail from the video and this return null value in the
imagesel.can anybody help me to solve this problem I am using YouTube URL .when I am using this code for the video that is in the main bundle then it is working fine.

Do this:
Firstly extract videoID from Video URL Link.
Now refer this link for getting thumbnail of video.

each youtube link has 4 thumbnail
http://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/1.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/2.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/3.jpg
this code is very good for
for example
i have this link:
http://www.youtube.com/watch?v=HPwyVw_6vsQ&feature=youtu.be
and the youtube video id is:
HPwyVw_6vsQ
and generated thumbnail from this link is:
http://img.youtube.com/vi/HPwyVw_6vsQ/1.jpg
this is very easy to use

if someone wants HQ image use this link
https://img.youtube.com/vi/<insert-youtube-video-id-here>/maxresdefault.jpg

If you have a YouTube watch page URL, and you want to get the thumbnail URL, the "correct" way to do that is to use oEmbed:
http://apiblog.youtube.com/2009/10/oembed-support.html
That way you don't have to attempt to parse the video id out of the URL.
But... what you really should be doing is using a iframe embed to display videos in your web page (or UIWebView). The YouTube API Terms of Service covers the supported ways of accessing YouTube content:
https://developers.google.com/youtube/terms

Related

how to get YouTube Video URL

I am looking for Youtube Downloader app .and to download Video Firstly I need to get the URL of the Running video.How do I get the url of the video which i play.
but when I play any video into the simulator it automatically gives me some information of the url..which is
2013-02-21 12:25:26.518 MyTube[682:14003] [MPAVController] Autoplay: Enabling autoplay
2013-02-21 12:25:26.518 MyTube[682:14003] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 0, on player: 1)
2013-02-21 12:25:26.518 MyTube[682:14003] setting movie path: http://r19---sn-a5m7lner.c.youtube.com/videoplayback?mt=1361429411&ipbits=8&fexp=919113%2C927902%2C916716%2C916612%2C901447%2C902545%2C920704%2C912806%2C902000%2C922403%2C922405%2C929901%2C913605%2C925006%2C906938%2C931202%2C908529%2C920201%2C930101%2C926403%2C901451&newshard=yes&key=yt1&signature=2AB1FC44B4EDA0C5DDF4E715FDCA19FFB16E0FF7.732382C58B3C8CBC4840D462940DFE2FEC9FBE53&source=youtube&sver=3&mv=m&expire=1361452937&ms=au&itag=36&el=watch&dnc=1&cp=U0hVRlRQUF9IUUNONV9MSlRKOjVNc1BwWTUxSVR2&upn=r3oQUqMCths&sparams=cp%2Cid%2Cip%2Cipbits%2Citag%2Cratebypass%2Csource%2Cupn%2Cexpire&ip=117.215.128.101&app=youtube_mobile&ratebypass=yes&yms=0PtNsY21DUs&id=2a147a30c3da7601
that means setting movie path url which I needed ..but it comes automatically in the output ..do can i fetch this url ...so that I can download
I am just Playing youtube video into the Webview
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://m.youtube.com"]]];
You can use the YouTube API to fetch the URL. Take a look here and here
Youtube is a little bit tricky in iOS because it's doesn't provide the real video link that obvisioulsy.
There is a good plugin clalled LBYoutubeView which handles to extract the real url for you. You can have a look at the link extractor if you just want to download the video...
Another opportunity is to use the gdata objective c client and and import the extracted link in an UIWebView. But keep in mind that the gdata client doesn't provide you with the real link like the framework above.
And be aware, that UIWebivews in simulators < 6.0 probably do not support playing a youtube video in a UIWebview.
At least here is an example of how to embed a youtube video directly in an UIWebView:
[self.webView loadRequest:[NSURLRequest requestWithURL:
[NSURL URLWithString:
[NSString stringWithFormat:#"%#%#", #"http://www.youtube.com/embed/", #"THEYOUTUBEID"]]]];
You can use HCYoutubeParser:
https://github.com/hellozimi/HCYoutubeParser
NSString *videoUrl = [NSString stringWithFormat:#"https://www.youtube.com/watch?v=%#", videoId];
NSDictionary *videos = [HCYoutubeParser h264videosWithYoutubeURL:[NSURL URLWithString:videoUrl]];
videoUrl = videos[#"small"];

How to make vimeo video autoplay on iPhone/iPad?

I'm trying to embed a vimeo video into my app using UIWebView.
Currently my code looks like this and it plays the video fine if you press play, but I would like it to play when the UIWebView loads and I'm not sure how to make that happen.
NSURL *videoURL = [NSURL URLWithString:#"http://player.vimeo.com/video/123456?autoplay=1"];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:videoURL];
UIWebView * SignUpVideo = [[UIWebView alloc] init];
MyVideo.frame = CGRectMake(0,125,781,481);
[self.view addSubview:SignUpVideo];
[MyVideo loadRequest:requestObj];
This is placed under -(void)viewDidLoad
The autoplay URL parameter doesn't work in Mobile Safari either. I'm thinking you may be out of luck unless you can get a URL for a direct stream. But in that case you could use the AVPlayer instead of a web view and have all of the flexibility you need.
Here is an interesting discussion about the vimeo direct link URLs: How can I find download links for vimeo videos? . However, according to that, vimeo doesn't allow that technique so you might want to take a look a the developer APIs here: https://developer.vimeo.com
Best regards.

How can I tweet videos from an iPhone app?

How can I tweet videos from an iPhone app programmatically ?
(the absence of programmatically caused me 3 vote downs :D)
Is there a way I can attach a video to a tweet ? Or should I upload the video somewhere else and just tweet the link ?
Any guidance in this regard is much appreciated. Thanks.
You need to upload the video, then link it in. You can't really 'attach' anything to a tweet.
i have same question, how to attach video to tweetsheet programmatically. only found code for setting tweetsheet text, image, or url link. looks like need to upload the video (eg. to amazon s3), then add video's url to tweetsheet ->
[tweetSheet setInitialText:#"Tweeting from my own app! :)"]
if (self.imageString) {
[tweetSheet addImage:[UIImage imageNamed:self.imageString]];
}
if (self.urlString) {
[tweetSheet addURL:[NSURL URLWithString:self.urlString]];
}
i checked the following tutorials/docs:
raywenderlich tutorial
(http://www.raywenderlich.com/21558/beginning-twitter-tutorial-updated-for-ios-6)
appcoda tutorial
(http://www.appcoda.com/ios-programming-101-integrate-twitter-and-facebook-sharing-in-ios-6/)
apple docs
(https://developer.apple.com/library/ios/documentation/NetworkingInternet/Reference/SLComposeViewController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40012205)

Load YouTube outside Application

I have a simple UIWebView showing a page including YouTube thumbnail. When I click it, it loads it inside the application, but I want it to be loaded outside application in the YouTube-app.
How can this be done?
Thanks.
It should be as simple as loading the YouTube-video-url like this:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.youtube.com/watch?v=abcde12345"]];
It won't work in the simulator because it doesn't have the YouTube-app, but it will work on the iPhone (i hope, untested).
(I also see that your accept-rate is pretty low, you should click the little ✔ next to the answer that you think is the best answer. That way people wondering about the same thing can find the most useful answer fast and the person posting the answer will be accredited.)
EDIT:
Here is an example of what you could do to catch the YouTube-urls and opening them in the YouTube-app instead of in your app:
- (BOOL)webView:(UIWebView *)wv shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
// Determine if we want the system to handle it.
NSURL *url = request.URL;
if ([url.host isEqual:#"youtube.com"] && ([url.query rangeOfString:#"watch"] != 0)) {
if ([[UIApplication sharedApplication]canOpenURL:url]) {
[[UIApplication sharedApplication]openURL:url];
return NO;
}
}
return YES;
}
This is not tested, but should work :)
From http://apiblog.youtube.com/2009/02/youtube-apis-iphone-cool-mobile-apps.html
Method 2: Embed the YouTube player in a UIWebView
No, the iPhone still doesn't do Flash, but if you haven't already
noticed, the Safari browser on the iPhone is clever enough to turn any
YouTube embed into a clickable thumbnail that launches the native
YouTube player app on the phone. You can take advantage of this
feature in your app by using a UIWebView. Here's how:
Set up a UIWebView in your app. You can make it part of a xib or create it programmatically. Size the UIWebView according to how large
you want the clickable thumbnail to be.
Grab the video url using the same method as the one described above.
Call the loadHTMLString:baseURL: method on the UIWebView instance with some carefully constructed HTML that contains the YouTube
embedded player code snippet and some supporting HTML to make sure
that the video thumbnail appears correctly. Set the base URL to the
URL of your website (it doesn't do anything here -- ordinarily
UIWebView uses it to handle relative URL links correctly).
The best way to illustrate this is with a code snippet. Note the use
of the viewport HTML meta parameter and the consistent use of width
and height parameters throughout.
// webView is a UIWebView, either initialized programmatically or
loaded as part of a xib.
NSString *htmlString = #" ";
[webView loadHTMLString:htmlString baseURL:[NSURL
URLWithString:#"http://www.your-url.com"]];
One of the biggest benefits of this approach is that your app does not
have to quit in order for the video to start playing. In fact, the
iPhone will keep your app running in the background while it fires up
the YouTube player to play the video. After the video finishes playing
(or when the user hits "Done"), the user is automatically taken back
to your app. This experience is very similar to watching embedded
YouTube videos in the iPhone Safari browser and is just as seamless.

UIWebView not playing YouTube videos

Running into an issue where I am trying to play a YouTube video through a custom UIViewController which contains a UIWebView. All web pages load fine in the UIWebView but if I go to play a YouTube video nothing is displayed. I can hear the video and the status bar is displayed at the top the screen but I can't see any video.
I've researched this a bit to find that...
-YouTube videos may not play in the simulator so I tried it on my device (iPhone 4 with iOS 4.1) to no avail
-There may be issues when trying to play a YouTube video when tethered and deploying through XCode so I tried deploying to my iPhone and then untethering. Video still does not play and I get the same results as noted above.
I'm suspicious that a MPMoviePlayer may be getting childed to the UIWebView but the view portion of that movie player is not being set for some reason which is why I'm not seeing it. Not completely sure about that.
I am seeing alot of threads on this issue but nothing has led me to a solution yet. If there is any input you can offer it would be greatly appreciated.
I Assume you're using Embed Video, i have created HTML file and inserted the Embed video tags and in my web view i use the following:
[WebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"AboutiPad" ofType:#"html"] isDirectory:NO]]];
it will work for both Simulator and devices this snippet is tested and is being used now, Good luck
Are you trying to play a youtube video with an https URL?
I've noticed that if I try to embed videos with https, they don't always work on some devices.
I basically used the info from this post: Embedding YouTube videos on
But made sure I ran my URL parameter through the following code before putting it into the HTML template:
NSRange range = [urlString rangeOfString:#"https"];
if (range.length == 5 && range.location == 0) {
urlString = [urlString stringByReplacingCharactersInRange:range withString:#"http"];
}