I use this code in my app to embed youtube video
NSString *embedHTML = #"\
<html><head>\
<style type=\"text/css\">\
body {\
background-color: transparent;\
color: transparent;\
}\
</style>\
</head><body style=\"margin:0\">\
<embed id=\"yt\" src=\"%#\" type=\"application/x-shockwave-flash\" \
width=\"%0.0f\" height=\"%0.0f\"></embed>\
</body></html>";
NSString *html = [NSString stringWithFormat:embedHTML, urlString, frame.size.width, frame.size.height];
The youtube video url is from urlString, like "http://www.youtube.com/v/QfWGRIlpNBE". And this code works fine.
My question is, if the video is in flash format, then it can not be played on iphone, and I got a slosh cross the play button.
How can I detect if youtube video is a flash format or H.264 format? I only have the url of the video.
If you need to know before you construct your HTML, I think the only way would be to use the YouTube API. You could query for the video in your question with the following:
http://gdata.youtube.com/feeds/api/videos?q=QfWGRIlpNBE&max-results=1&v=2&format=1
There are no results for that video ID in H.263.
See http://code.google.com/apis/youtube/2.0/reference.html#formatsp for API doc.
Otherwise, you could just use an <iframe>:
http://apiblog.youtube.com/2010/07/new-way-to-embed-youtube-videos.html
Related
I am playing youtube video in uiwebview using following code
NSString *embedHTML = #"\
<html><head>\
<style type=\"text/css\">\
body {\
background-color: transparent;\
color: white;\
}\
</style>\
</head><body style=\"margin:0\">\
<embed id=\"yt\" src=\"http://www.youtube.com/embed/%#?autoplay=0&showinfo=0&controls=0\" type=\"application/x-shockwave-flash\" \
width=\"%0.0f\" height=\"%0.0f\"></embed>\
</body></html>";
NSString *html = [NSString stringWithFormat:embedHTML, videoToken, videoView.frame.size.width, videoView.frame.size.height];
[videoView loadHTMLString:html baseURL:nil];
My problem is that until the youtube video is not loaded I want to show loading or some thing to say it is being loaded. I tried to detect in webview did finish load, but it comes 2-3 times in that method.
Please help
If you want to detect video is loaded or not then use below method , it is delegate method of UIWebview
You must set delegate of UIWebview in your View Controller Class.
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
//your code here
}
Let me know it is working or not!!!
Happy Coding!!!!
I want implement play and stop button same sd youtube when webview is loaded with Youtube URL. I used below code but when it loads in webview it starts playing (auto-play). I just want to load it in webview and not auto-play it. How can I do this?
This is my code:
UIWebView *videoview = [[UIWebView alloc] initWithFrame:CGRectMake(10,80,275.0,150)];
NSURL *nsurl=[NSURL URLWithString:strpreview];
NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl];
[videoview loadRequest:nsrequest];
[self addSubview:videoview];
Thanks in advance
Here is the code to create an load an embedded video in iPhone using iFrame
NSString *yourURL = #"http://www.cloudstringers.com:14556/ingCloud/users/400010003/mp4_320p/efda2f8a618be8e4a36b81d31251752820130710115909.mp4";
NSString *embedHTML =[NSString stringWithFormat:#"\
<html><head>\
<style type=\"text/css\">\
body {\
background-color: #666666;\
padding:%f %f %f %f;\
color: blue;\
}\
</style>\
</head><body style=\"margin:0\">\
<iframe height=\"%f\" width=\"%f\" title=\"YouTube Video\" class=\"youtube-player\" src=\"%#" ></iframe>\
</body></html>",paddingTop,paddingRight,paddingBottom,paddingLeft,videoHeight,videoWidth,yourURL];
[self.webView loadHTMLString:embedHTML baseURL:nil];
Hope this helps. Do let me know if you need anything more.
I am using the below code to play youtube url:
NSString *youtubeUrl = [NSString stringWithFormat:#"http://www.youtube.com/v/%#",[photo videoUrl]];
[self embedYouTube:[youtubeUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] frame:CGRectMake(10, 120, 300, 200)];
- (void)embedYouTube:(NSString*)url frame:(CGRect)frame
{
NSString* embedHTML = #"\
<html><head>\
<style type=\"text/css\">\
body {\
background-color: black;\
color: black;\
}\
</style>\
</head><body style=\"margin:0\">\
<embed id=\"yt\" src=\"%#\" type=\"application/x-shockwave-flash\" \
width=\"%0.0f\" height=\"%0.0f\"></embed>\
</body></html>";
NSString* html = [NSString stringWithFormat:embedHTML, url, frame.size.width, frame.size.height];
if(videoView == nil) {
videoView = [[UIWebView alloc] initWithFrame:frame];
videoView.layer.borderColor = [[UIColor blackColor] CGColor];
[self.view addSubview:videoView];
[videoView setHidden:NO];
}
[videoView loadHTMLString:html baseURL:nil];
}
User need's to tap on the webview to play this video. Can't it directly load the video without tapping on the play icon?
add a parameter autoplay=1 to the URL, like this:
NSString *youtubeUrl = [NSString stringWithFormat:#"http://www.youtube.com/v/%#?autoplay=1",[photo videoUrl]];
Check this way to embed your play, which support Auto PLay
https://developers.google.com/youtube/player_parameters
You should check LBYouTubePlayerController which uses the MoviePlayer component to load youtube videos and it's a lot easier to customize things, like autoplay feature.
I think the short answer is, if you're displaying videos with a webView autoPlay is no longer allowed per Apple guidelines. The docs specifically state:
Warning: To prevent unsolicited downloads over cellular networks at
the user’s expense, embedded media cannot be played automatically in
Safari on iOS—the user always initiates playback.
This same doc is referenced from Google Developer / YouTube API docs.
I am working with mp4 videos hosted by my company, not YouTube.
I am using the following code to create a clickable thumbnail in a UIWebView:
videoButtonHTML = [videoButtonHTML stringByAppendingFormat:#"<body bgcolor=\"#000000\"><img src=\"%#\" width=\"120\" height=\"90\" border=\"0\" type=\"application/x-shockwave-flash\"/></body>", videoURL, self.imageLink];
[videoButtonWebview loadHTMLString:videoButtonHTML baseURL:nil];
This works fine at first. It creates the thumbnail and plays the video. The problem is that, when you close the video, the thumbnail image disappears. I still have the "blank" Quicktime play image. I really want to keep the image, though.
I've tried this both with and without the shockwave tag - same result. I found an embedYoutube function in a tutorial. It works great with YouTube videos, but not with mp4 videos. Here's that code, in case it helps:
- (void)embedYouTube1:(NSString *)urlString frame:(CGRect)frame {
NSString *embedHTML = #"\
<html><head>\
<style type=\"text/css\">\
body {\
background-color: transparent;\
color: white;\
}\
</style>\
</head><body style=\"margin:0\">\
<embed id=\"yt\" src=\"%#\" type=\"application/x-shockwave-flash\" \
width=\"%0.0f\" height=\"%0.0f\"></embed>\
</body></html>";
NSString *html = [NSString stringWithFormat:embedHTML, urlString, frame.size.width, frame.size.height];
UIWebView *videoView = [[UIWebView alloc] initWithFrame:frame];
[videoView loadHTMLString:html baseURL:nil];
[self.view addSubview:videoView];
[videoView release];
}
Any idea what's going on?
Try saving the image as NSData, maybe to your NSUserDefaults (when the video is loaded), then you can display the thumb from defaults, instead of the video itself (when the video is not loaded).
Good Morning,
I am an iOS/Mac Developer.
I am developing an application that grab flv link from a website: now I want to play this flv file in streaming.
I find in AppStore BUZZPlayer, an application that can play flv video streaming: http://itunes.apple.com/it/app/buzz-player/id389744738?mt=8
Searching on Google I find out that exists ffmpeg for iPhone, so, my question is how can I stream a FLV Video with ffmpeg on iPhone?
A sample code is very appreciated!
Thank You.
P.S. Sorry for my poor English...
The solution I would recommend would be to display a kind of web view, and then put the video embedded in the HTML.
Like generate some html code with your flv link.
Here is an example of what I'm talking about.
- (void)embedYouTube:(NSString*)url frame:(CGRect)frame {
NSString* embedHTML = #"\
<html><head>\
<style type=\"text/css\">\
body {\
background-color: transparent;\
color: white;\
}\
</style>\
</head><body style=\"margin:0\">\
<embed id=\"yt\" src=\"%#\" type=\"application/x-shockwave-flash\" \
width=\"%0.0f\" height=\"%0.0f\"></embed>\
</body></html>";
NSString* html = [NSString stringWithFormat:embedHTML, url, frame.size.width, frame.size.height];
if(videoView == nil) {
videoView = [[UIWebView alloc] initWithFrame:frame];
[self.view addSubview:videoView];
}
[videoView loadHTMLString:html baseURL:nil];
}
hope this helps in any way.
I used the kxmovie (https://github.com/kolyvan/kxmovie) as example
I searched in many examples but only this code worked