Handle control buttons of UIwebview youtube video player - iphone

I'm creating a youtube videos player which can play a list of youtube video ( given a list of video id). I embedded youtube video into a UIWebview as following:
NSString *htmlFormat = #"<html><head><body style=\"margin:0\"><embed id=\"yt\" src=\"%#\" type=\"application/x-shockwave-flash\" width=\"40\" height=\"30\"></embed></body></html>";
NSString *url = [NSString stringWithFormat:#"http://www.youtube.com/watch?v=%#", videoId];
NSString *html = [NSString stringWithFormat:htmlFormat, url];
[webView loadHTMLString:html baseURL:nil];
What i need are:
Next video is played automatically when player finishes playing current one.
Next video is played when user tap next button in players' control panel
Stop playing list if user tap 'Done' button.
My approach is handling events that may be sent out when player finish playing, users tap control buttons, so i can modify html content to load other videos.
My question are:
Is there better way to play a list of youtube video given a list of video ids?
How to handle such those events?
I found some solutions that suggest handle notification UIMoviePlayerControllerDidExitFullscreenNotification and UIMoviePlayerControllerDidEnterFullscreenNotification, but I can not distinguish between control buttons' events and finish playing event (movie player controller exits fullscreen mode in all the cases). Some suggest using HTML <video> tag, but i dont think it possible.

Related

When my embed youtube video finished I can't play it again?

I have a working webview in Titanium with an embeded youtube video. The video plays nice, I can stop it, resume it and so on. But when the video plays to the end and I press "done". The webview goes black with the text: YouTube. Nothing else. I would like there to be the same thumb and playbutton as before I played the video.
My embeded code looks like this:
html:'<html><head></head><body style="margin:0"> <embed id="yt" src="'+tubeURL+'" type="application/x-shockwave-flash" width="150" height="113"></embed></body></html>',
I've googled this problem for days now. I hope someone can help me here.
Cheers
//Martin
EDIT: This solved it. Put &controls=1&rel=0 in the end of the URL.
YouTube players can be embedded in a web page using either an < iframe> tag or an < object> tag.
By appending parameters to the SWF or IFrame URL, you can customize the playback experience in your application. For example, you can automatically play videos using the autoplay parameter or cause a video to play repeatedly using the loop parameter or in your case hide or show controls.
controls
Values: 0, 1, or 2. Default is 1. This parameter indicates whether the video player controls will display. For AS3 players, it also defines when the Flash player will load:
controls=0 – Player controls do not display in the player. For AS3 players, the Flash player loads immediately.
controls=1 – Player controls display in the player. For AS3 players, the Flash player loads immediately.
controls=2 – Player controls display in the player. For AS3 players, the Flash player loads afer the user initiates the video playback.
The correct answer for your question would be controls=2.
SOURCE INFO: https://developers.google.com/youtube/player_parameters#controls

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.

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.

Use Vimeo videos inside iPhone/iPad app

our client's video archive is hosted on vimeo, so I want to know if it is possible to use vimeo videos inside of iOS app so that user could press button and get fullscreen video playing in default video player. Is there any kind of API available for that?
upd: I know that in 2010 there was same question on SO, but maybe things changed during last year.
Get the video id, and load it into a webview using the vimeo player url. It will open the quicktime player in full screen mode on tap of the play button.
urlAddress = [NSString stringWithFormat:#"http://player.vimeo.com/video/%#",videoID];
NSURL *url = [NSURL URLWithString:urlAddress];
self.requestObj = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:requestObj];
You can use YTVimeoExtractor to extract the mp4 url that is usable in MPMoviePlayerViewController.

Is there anyway to autoplay online content audio file on ipad

I want to play audio file on ipad which is located on some server. but thing is I want to autoplay audio file using HTML5. Please suggest me the way.
Thanks
The autoplay attribute is purposely disabled on iPhone and iPad:
In Safari on iOS (for all devices,
including iPad), where the user may be
on a cellular network and be charged
per data unit, preload and autoplay
are disabled. No data is loaded until
the user initiates it. This means the
JavaScript play() and load() methods
are also inactive until the user
initiates playback, unless the play()
or load() method is triggered by user
action. In other words, a
user-initiated Play button works, but
an onLoad="play()" event does not.
Having said that there are some hacks for iOS 3 and iOS 4 to work around this with JavaScript. On iOS 3 you can create a link element and then simulate a click event to trigger the media element to play; on iOS4 you can simply call the load() and play() methods directly on the element.
Try this
NSURLRequest *request = [[NSURLRequest alloc] initWithURL: [NSURL URLWithString:#"www.example.com/play.mp3"] cachePolicy: NSURLRequestUseProtocolCachePolicy timeoutInterval: 10];
[myWebView loadRequest: request];
[request release];
Hope this helps!!!