starting embedded youtube video from a specific time - ios

NSString *linkVideo = #"http://www.youtube.com/watch?v=XabyZDSzMJ0&t=0m38s";
NSString *htmlString = [NSString stringWithFormat:#"<iframe width=\"420\" height=\"315\" src=\"http://www.youtube.com/embed/XabyZDSzMJ0\" frameborder=\"0\" allowfullscreen></iframe>", linkVideo];
// Load the html into the webview
[self.myWebView loadHTMLString:htmlString baseURL:nil];
Hi, I've embedded a youTube video in my iPhone app.
How can I force starting this video from sec 38th?
thanks a lot!

Im not a expert and probly wrong but i think &t=0m38s" is for embeded video links, you might have to use &start=38".
"start=" only takes seconds also
Im probly wrong but worth a try

NSString *linkVideo = #"http://www.youtube.com/watch?v=XabyZDSzMJ0&start=38";
This starts the youtube video at the 38th second.

I think this ight be useful:
http://www.mattcutts.com/blog/link-to-youtube-minute-second/
Thnx,

Related

How do I play YouTube videos with iOS-GTLYouTube library?

I'm trying to play YouTube videos using the iOS-GTLYouTube library. I just finished the query code for my videos and got back a few GTLYouTubeVideo objects. So after I got them, then what? How do I play it? I've searched the web but found nothing.
You can't play videos with the GTLYouTube library, you can only use it to search the API for video information.
After retrieving the Video ID of the video you want to play, you can load that id into the iFrame up in a UIWebView.
NSString *videoID = #"HCdUubr70i8"; // the video ID returned from your API query
// Adjust the width and height to your liking, I just pass in the view's frame width and height
NSString *str = [NSString stringWithFormat:#"<html><body style='margin:0px;padding:0px;'><script type='text/javascript' src='http://www.youtube.com/iframe_api'></script><script type='text/javascript'>function onYouTubeIframeAPIReady(){ytplayer=new YT.Player('playerId',{events:{onReady:onPlayerReady}})}function onPlayerReady(a){a.target.playVideo();}</script><iframe id='playerId' type='text/html' width='%#' height='%#' src='http://www.youtube.com/embed/%#?enablejsapi=1&rel=0&playsinline=1&autoplay=1' frameborder='0'></body></html>", self.view.frame.size.width, self.view.frame.size.height, videoID];
UIWebView *webView = [UIWebView ...];
[webView loadHTMLString:embedHTML baseURL: [[NSBundle mainBundle] bundleURL]];
Google also provides their own UIWebView wrapper class, youtube-ios-player-helper, which makes YouTube video playback on iOS devices a little easier.

How to get a video to play in UIWebView (video is in a ALAsset group)?

Okay maybe the headline is somehow disturbing, I hope to state this so you can understand my problem.
So I have a scrollview which has paging enabled. I want to build something like iOS Photo App.
I load the photos and videos which are on the device via ALAsset and store them in a group.
Now i want to present each object on a separate subview of the scrollview.
For the pictures it is working fine. But for videos I cant make it work.
Here is what i did and what did not work:
First:
UIWebView *webView = [[UIWebView alloc] initWithFrame:frame];
NSString *embedHTML = [NSString stringWithFormat: #"<html><head><style></style></head><body>\
<video id='video_with_controls' width=\"%0.0f\" height=\"%0.0f\" controls>\
<source src='%#' type='video/MOV'/></video><ul>\
</body></html>", self.mainScrollView.frame.size.width, self.mainScrollView.frame.size.height, [assetRepresentation url]];
[webView loadHTMLString:embedHTML baseURL:nil];
then:
UIWebView *webView = [[UIWebView alloc] initWithFrame:frame];
NSString* embedHTML = [NSString stringWithFormat:#"<video controls> <source src=\"%#\"> </video>", [assetRepresentation url];
[webView loadHTMLString:embedHTML baseURL:nil];
Also I tried to store it in NSData first and then load it from there, but that causes memory problems and wont work.
Any help is highly appreciated!
Edit: As I think UIWebView is the thing that matches the iOS App visually at most, I want to use this and not for example the MPMoviePlayer .. if I am wrong there I would be glad to know how / what else looks like the original App
I guess the video url is local thats why its not working in UiWebView
so the solution would be this:
in delegate method webviewdidstartload,set up MPmovieplayer controller to play inside a UiView and yes it will look like original app as you will be playing it in a view
something like this:
Add MPMoviePlayerController's view to a UIView
When you movie file is located locale you must set the baseURL to your MainBundle and put the full path in the "src"-tag.

UIWebView youtube iframe api autoplay/playsinline quit working in iOS7

This code has worked really well to auto-play video inline in an iOS 6 uiwebview. However, I upgraded to iOS 7 and now my video will not auto-play. Sometimes video will auto-play and sometimes it won't. It will auto-play about 10% of the time. Most of the time I get a spinning wheel. If I remove &playsinline=1 from the src tag it will auto-play fullscreen (not what I want). I spent a lot of time creating a custom player for this app and now it won't work correctly. Any help is greatly appreciated.
_youTubeWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 20, 320, 184)];
_youTubeWebView.delegate = self;
_youTubeWebView.scrollView.bounces = NO;
_youTubeWebView.allowsInlineMediaPlayback = YES;
_youTubeWebView.mediaPlaybackAllowsAirPlay = YES;
_youTubeWebView.mediaPlaybackRequiresUserAction = NO;
[self.view addSubview:_youTubeWebView];
NSString* embedHTML = [NSString stringWithFormat:#"<html><body style='margin:0px;padding:0px;'><script type='text/javascript' src='http://www.youtube.com/iframe_api'></script><script type='text/javascript'>function onYouTubeIframeAPIReady(){ytplayer=new YT.Player('playerId',{events:{onReady:onPlayerReady}})}function onPlayerReady(a){ a.target.playVideo(); }</script><iframe id='playerId' type='text/html' width='%#' height='%#'src='http://www.youtube.com/embed/%#?enablejsapi=1&rel=0&playsinline=1&controls=0&showinfo=0' frameborder='0'></body></html>", w, h, videoId];
[_youTubeWebView loadHTMLString:embedHTML baseURL:nil];
Here's a link to a quick test file. videoPlayerTest.zip
This sounds like the following open bug against the Youtube iframe player API:
Issue 5204: js iframe api playVideo() doesn't play video in iOS 7
http://code.google.com/p/gdata-issues/issues/detail?id=5204
You can fix the autoplay behavior by changing the baseURL to:
[[NSBundle mainBundle] resourceURL]

iOS Force user to watch a YouTube video

Im using this code to play a commercial video in my iOS application:
- (void)embedYouTube:(NSString *)urlString frame:(CGRect)frame {
UIWebView *videoView = [[UIWebView alloc] initWithFrame:frame];
[videoView loadHTMLString:[NSString stringWithFormat:#"<iframe width=\"%f\" height=\"%f\" src=%# frameborder=\"1\" allowfullscreen></iframe>",frame.size.width-10,frame.size.height-10,urlString] baseURL:nil];
[self.view addSubview:videoView];
[videoView release];
}
I want to force the user to see the video and close the UIWebView once the video is completed without allowing the user to shut the video off.
I think if i can make the Video plays automatically and set the:
videoView.userInteractionEnabled = NO;
that will force the user to watch it.
My Questions:
1- How to force the UIWebView using <iframe> ?
2- How to detect if the video finished playing?
3- Is there any other way (Better One) to play YouTube videos in iOS?
Glad to hear any other ideas or answers, Thanks in advance.
try this:
videoView.userInteractionEnabled = NO;
and you can create a UIButton to close the video.
you can use LBYoutube for youtube videos. see following link
LBYouTube

Embed Youtube videos :- with contains content from * , it is restricted from playback on certain site

How to embed a Youtube video that has copyrighted content in it.
For example when you try playing this video(http://www.youtube.com/embed/ADBKdSCbmiM) in a UIWebView it says
This Video Contains content from Vevo. It is restricted from playback on certain sites
How would I go about getting videos like this to play in an embedded player or a custom player that I would make using MPMoviePlayer or such. I know this is possible as following app does this. (http://itunes.apple.com/us/app/audioviz-view-your-songs-on/id547001249?mt=8)
Edit
Few videos play in browser but in iOS Simulator its showing
This video contains content from SME . It is restricted from playback on certain site
Thanks for all the help!
You can use player vars while initializing youtube sdk:
NSDictionary *playerVars = #{
#"origin" : #"http://www.youtube.com",
};
[self.playerView loadWithVideoId:#"KOvoD1upTxM" playerVars:playerVars];
Enjoy!
To play the youtube video using uiwebview:
First check if your youtube URL is played or not in browser. If the video doesn't play in the browser it won't play in the device either
You only check in the device; the video doesn't play in simulator
- (void) displayGoogleVideo
{
CGRect rect = [[UIScreen mainScreen] bounds];
CGSize screenSize = rect.size;
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,screenSize.width,screenSize.height)];
webView.autoresizesSubviews = YES;
webView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
NSString *videoUrl = #"http://www.youtube.com/v/oHg5SJYRHA0"; // valid youtube url
NSString *htmlString = [NSString stringWithFormat:#"<html><head><meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 212\"/></head><body style=\"background:#F00;margin-top:0px;margin-left:0px\"><div><object width=\"320\" height=\"480\"><param name=\"movie\" value=\"%#\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"%#\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"320\" height=\"480\"></embed></object></div></body></html>",videoUrl,videoUrl] ;
[webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:#"http://www.youtube.com"]];
[window addSubview:webView];
[webView release];
}
If you're embedding on a mobile app, you need to set your Referer in your request header for the video. Otherwise, Youtube automatically blacklists you if your Referer field is left blank.
I answered this in detail here. I was experiencing this myself and I fixed it in my case (iOS app using React Native). I can play Vevo, WMG, and all other restricted content now.

Resources