Can't play video using webview - iphone

I am using webview to show the video thumb in my application, all is working fine and I can see the video thumb there in my application. But when I tap on the webview It shows loading the video but movie player never shown in my application and status bar disappears. but when I use same code in another sample application, it plays the video successfully. I am not able to find the issue. Here is my code segment
NSString *vimeoURL = [NSString stringWithFormat:#"http://player.vimeo.com/video/%#?title=0&byline=0&portrait=0", [stepDic objectForKey:video_id]];
NSString *htmlStr = [NSString stringWithFormat:#"<iframe src=\"%#\" width=\"100\" height=\"100\" frameborder=\"0\" webkitAllowFullScreen allowFullScreen></iframe>", vimeoURL];
[aWebView loadHTMLString:htmlStr baseURL:nil];
[self.view addSubview:aWebView];

Related

Get notification when play button appears in embedded video with UIWebView

i'm using webviews into my app to embed videos, in this way
NSString *embedHTML = #"<iframe width=\"300\" height=\"250\" src=\"http://www.youtube.com/.....\" frameborder=\"0\" allowfullscreen></iframe>";
NSString *html = [NSString stringWithFormat:embedHTML];
[_webView loadHTMLString:html baseURL:nil];
I'd like to get notified when the play button appears, in order to create and stop an activity indicator... I've used
- (void)webViewDidFinishLoad:(UIWebView *)webView
but it's not sufficient... when the webview finishes loading and the activity indicator stops, the playbutton appears 2-3 seconds later...
How can i synchronize the activityindicator stop with the playbutton appearance?
Thanks

Youtube video in UIWebview not working

Using this code to play YouTube video in UIWebView
- (void)embedYouTube {
UIWebView *webView = [[[UIWebView alloc] initWithFrame:self.view.bounds] autorelease];
webView.autoresizesSubviews = YES;
webView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
// iframe
videoHTML = [NSString stringWithFormat:#"\
<html>\
<head>\
<style type=\"text/css\">\
iframe {position:absolute; top:50%%; margin-top:-130px;}\
body {background-color:#000; margin:0;}\
</style>\
</head>\
<body>\
<iframe width=\"560%%\" height=\"315px\" src=\"%#\"http://www.youtube.com/embed/j9CukQje2qw\" frameborder=\"0\" allowfullscreen></iframe>\
</body>\
</html>", videoURL];
[videoView loadHTMLString:videoHTML baseURL:nil];
}
When i click on this LaunchVideo UIButton all it shows black screen on iOS device
-(void)LaunchVideo:(id)sender
{
self.videoURL = #"http://www.youtube.com/embed/j9CukQje2qw";
WebViewController *webViewController = [[[WebViewController alloc] initWithNibName:nil bundle:nil] autorelease];
webViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
webViewController.videoURL = self.videoURL;
[self presentModalViewController:webViewController animated:YES];
}
If anyone can point out what i m missing or doing wrong in this code. Why youtube video is not showing. Not using interface builder doing programmtically. Got this project code from web. Tried this project code on ios device it works fine for that project but when applied its code in my project then it is not working. Only difference that his projectcode from web uses interface builder and i am doing it programmtically.I dont get it.
Please help what is wrong with this code.
Thanks for help.
Here is another way to load the youtube video into your app. First, put a UIWebView into your interface and size it to how big you want the video should show (there will be a button to make it full screen), then make an IBOutlet to it, so you can change its properties of hidden (to make it pop up and go away) Here is some code. In the code there is a method used called webviewshow, this calls a simple method that basically just says
webview.hidden = NO;
webviewbutton.hidden = NO;
Then there is a button that also pops up that makes the web view go away when tapped. Here is the code to load the youtube video into the web view
// Create your query ...
NSString* searchQuery = [NSString stringWithFormat:#"http://www.youtube.com/embed/j9CukQje2qw];
// Be careful to always URL encode things like spaces and other symbols that aren't URL friendly
searchQuery = [searchQuery stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
// Now create the URL string ...
NSString* urlString = searchQuery;
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
[webView loadRequest:request]; currentTimer= [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:#selector(webviewshow) userInfo:nil repeats:NO];;
It waits 2 seconds (usual wait time for most connections) until the web view is shown, so the page is loaded and the user does not have to watch it load.
Then when you want to make the video go away, make a method to close the web view like so
- (void) makewebviewGoAway {webview.hidden = YES; webviewbutton.hidden = YES;}
Hopefully, that was helpful. IF you need further help or explanation, just comment off of this.

Youtube video causes Main View to open afterwards.

I just implemented a youtube video view on my app, but when I close the youtube video after watching it.. it wont close. It opens the main view controller then places it above all other view controllers (i think). heres how I am showing the youtube video:
Inside MyViewController.m:
NSString *lessonHTML = #"http://www.youtube.com/watch?v=0P7UgKjzndo";
NSString *ytHtml = #"<html><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:ytHtml, lessonHTML, youtubeView.frame.size.width, youtubeView.frame.size.height];
NSLog(#"HTML String: %#",html);
[youtubeView loadHTMLString:html baseURL:nil];
when the thumbnail is pressed it loads the video. Then when I click 'done' it bring me back to my main ViewController not the one I was in.
Im using Storyboards just incase its something to do with that.
Beer and upvotes for epic answers thanks!

How to play video from URL in Ipad?

In my application i get the links of video from server in UITableview .all these link are store on Sever in Textfile,i get all these link from sever one by one and assign each to cell in UITableview.all these i done succefully but i want when i click on any cell in UITableview its play the video in next view.here is my code.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
nextview *dvController = [[nextview alloc] initWithNibName:#"nextview" bundle:nil];
[self presentModalViewController:dvController animated:YES];
strFile = [Listdata objectAtIndex:indexPath.row];
NSLog(#"test=%#",strFile);
[dvController release];
}
and in next view i assign the link which i store in "strFile" to MPMoviePlayerController here is my code.
-(void)viewDidAppear:(BOOL)animated
{
NSLog(#"mytest=%#",strFile);
NSURL *url = [NSURL URLWithString:strFile];
NSLog(#"myurl=%#",url);
myplayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
myplayer.view.frame = CGRectMake(0, 0,900, 700);
[self.view addSubview:myplayer.view];
[myplayer play];
}
In NSlog i see the link but its not play in MPMoviePlayerController.Any one can guide me that what mistake i make.thanx in advance.
#prince : can u tell me what url you are getting in NSLog?? i think u're mistaken in getting the url.
we can get url either by
url = [NSURL fileURLWithPath:strUrl];
else
url = [NSURL URLWithString:strUrl];
try it out once.
You probably shouldn't be setting the frame and adding to the subview, You may be confused with MPMoviePlayerViewController. Try this...
-(void)viewDidAppear:(BOOL)animated {
NSLog(#"mytest=%#",strFile);
NSURL *url = [NSURL URLWithString:strFile];
NSLog(#"myurl=%#",url);
myplayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
myplayer.scalingMode = MPMovieScalingModeAspectFill;
[myplayer play];
}
EDIT disregard my code, you can't directly play a YouTube video in MPMoviePlayerController. Check this Post instead Play YouTube videos with MPMoviePlayerController instead of UIWebView
to youtube video play inside app is to create a UIWebView with the embed tag from Youtube for the movie you want to play as the UIWebView's content. UIWebView will detect that the embedded object is a Youtube link, and the web view's content will be the youtube preview for the video. When your user clicks the preview, the video will be shown in an MPMoviePlayerController. try this link:
http://iphoneincubator.com/blog/audio-video/how-to-play-youtube-videos-within-an-application
Unfortunately, there's no way to directly play a youtube video with MPMoviePlayerController because youtube does not expose direct links to the video files.

How to start an embedded YouTube video at a certain timestamp in iphone

I want to start an embedded youtube video from a timestamp. I know how to do it on browsers but that does not seem to work on iPhone. Here is a detailed tutorial by MATT CUTTS.
Start an embedded video at a certain timestamp
In above link you can see if we append #t=31m08s or &start=200 in url it works but when i use same url inside UiWebView, default youtube player starts video from first frame. Can anyone have an idea or have implemented same. I am using UIWebView with embed tag to play youtube video. I am using below embed tag inside UIWebView.
<embed id="yt" src="http://www.youtube.com/watch?v=dsFQ9kM1qDs" type="application/x-shockwave-flash" width= "500" height="400"></embed>
Below is the code i am using to play this video in UIWebView
- (IBAction) playYoutube {
[self embedYouTube:#"http://www.youtube.com/watch?v=dsFQ9kM1qDs#t=2m08s"];
}
- (void)embedYouTube:(NSString*)url
{
[webView setFrame:CGRectMake(0, 0, 480, 320)];
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, webView.frame.size.width, webView.frame.size.height];
[webView loadHTMLString:html baseURL:nil];
}
According to the Youtube API team there no way to do this with iPhone/iPad etc. - see https://groups.google.com/group/youtube-api-gdata/browse_thread/thread/ef4f434347622448/0f65f465d671d74c
Try adding ?t=1m10s at the end of the link
E.g. src="https://youtu.be/dsFQ9kM1qDs?t=1m10s"
Note: Make sure that you use youtu.be link (the link that you get when you click share button on YouTube) and not youtube.com link