Issue in playing vimeo video in webview - iphone

In my app there is a vimeo video. I have opened it in WebView using following code ;
NSURL *url = [NSURL URLWithString:#"https://vimeo.com/47278503"];
NSURLRequest *req = [NSURLRequest requestWithURL:url];
webview.delegate = self;
[webview loadRequest:req];
And place one cancel button above the WebView to close the vimeo video.
But the problem is that audio still plays after closing the WebView by clicking that cancel button.
And another issue is that on viewing full screen, video is not showing ,only audio plays in background and after clicking cancel button the video is playing in background.
UPDATE :
There is a similar issue in link. I have tried it's code but it doesnt work. I have written the code
[self.view addSubview:self.view.window.rootViewController.view];
in tableview's didSelectRowAtIndexPath() method. (and this tableview is in popover).
I have also tried [self.view addSubview:self.view.window.rootViewController.view]; in WebView's viewDidLoad() , but it doesnt work.
What can be the issue ?
Thanks.

for stop BG sound. you just remove, release and set nil to your UIWebView.

Related

Play a video from a server without exiting the app - Cocoa Touch, iPhone

Basically I have 8 thumbnails which are buttons. When each button is tapped, it launches the video which is located on my server. However at the moment, when a thumbnail is tapped, the video launches in safari and exits the app. I want it so the video launches in the app instead of exiting it, so once the user has finished watching the video, they are then returned to the app.
Here is the code I've used.
-(IBAction)goAbv1:(id)sender; {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://mywebsite.com/video.mp4"]];
}
Try this if you are on iOS 3.2+
NSString *videoURLString = #"http://MypathtoIphoneCompatibleVideoMp4";
NSURL *videoURL = [NSURL URLWithString:videoURLString];
MPMoviePlayerViewController *moviePlayerView = [[[MPMoviePlayerViewController alloc] initWithContentURL:videoURL] autorelease];
[self presentMoviePlayerViewControllerAnimated:moviePlayerView];
presentMoviePlayerViewControllerAnimated will handle the modalviewcontroller and put it on top of the stack automatically so the video can be played. This should work easily.

YouTube - Play automatically

I have an UIButton. When this button is pressed, I load a WebView with the youtube video:
- (IBAction)buttonAction:(id)sender {
UIWebView *webView = [[UIWebView alloc] initWithFrame:[MyButton frame]];
NSString *htmlString = #"<html> (...) </html>"; // HTML w/ the YouTube iFrame
webView.mediaPlaybackRequiresUserAction = NO;
[webView loadHTMLString:htmlString baseURL:nil];
[self.view addSubView:webView];
}
The problem is that when it happen, I have this result:
I want to start playing the video right after I load the WebView.
Any tip/solution?
Thanks!
I would suggest creating an html page that is a stand alone page that will use the youtube player api. Since your creating an html page already just have the uiwebview use the stand alone site that you have created and then you can use the autoplay features built into the youtube player. I can give more detail but if you can not use a stand alone html site as your option that this will be a worthless answer and thus anything else that I add will not help you.

How to program UItoolbar buttons to load a new website in UIWebView?

I am working on an IPhone app and i have a UIWebview that by default loads a url.
I need to create a UIToolbar with three buttons under UIWebview which will allow users to hit the buttons and load a new url in UIWebview?
you have to add three buttons to your toolbar( This can be easily done by using the Interface builder(IB) and connect them to there respective IBAction in the IB.
now when tap on a a button you can do like this.
you have a UIWebView say myWebView //declared in .h file and properly linked with the your View using IB.
when you are done with the basic initialization
for button1 press
-(IBAction)button1:(id)sender
{
NSURL *url = [NSURL URLWithString:#"http://www.google.com"];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[myWebView loadRequest:requestObj];
}
so by clicking on the button1 google webpage is loaded in your webView.
do the same for other button also.
:)
These methods and properties of UIWebview maybe help:
- (void)reload;
- (void)stopLoading;
- (void)goBack;
- (void)goForward;
#property(nonatomic,readonly,getter=canGoBack) BOOL canGoBack;
#property(nonatomic,readonly,getter=canGoForward) BOOL canGoForward;
#property(nonatomic,readonly,getter=isLoading) BOOL loading;

uiwebview youtube starting in landscape thumbnail does resize on rotation

I have navigation controller with a tableview. When you click on one of the cells it pushes on a view with a uiwebview on it. You are taken to a YouTube page.
When you are on the table view in portrait and click on a cell you see the youtube page in portrait. Changing your orientation the video thumbnail does not refresh. So the thumbnail is smaller. This is fine. I actually prefer it smaller. All the content that would consume 2 lines will then consume 1 line. So in other words everything else adjusts for the new dimensions.
The problem comes in when you start off in landscape. Since the thumbnail doesn't resize on orientation change, changing to portrait mode, the image now goes off the screen, while the rest of the content adjusts correctly.
[webVIew refresh];
does work but it obviously loads the entire page again. So depending on the connection there will be a flicker or possibly the site will go white until its finished loading (on slower connections).
I also tried load the website in an iframe. I asked a similar question yesterday, this was for local pages i was creating. The answer to that question was to put <meta name='viewport' content='width=device-width; initial-scale=1.0; maximum-scale=1.0;'> in the head. So I tried that with an iframe going and getting the page. That seemed like a dumb hack to begin with, but i was willing to go there. It wouldn't even load the page at all. I guess because the youtube page i'm loading redirects to yet other page. Upon further research it seemed like there were other issues with the iframe such as scrolling.
So my question is how can i:
A. Get just the thumbnail to resize/reload on orientation change
OR
B. Get the thumbnail to load in the dimensions it would load in portrait mode all the time, even if it was started in landscape.
You should override this method in your UIViewController class and do the resizing there:
(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;
I found the answer, maybe someone could explain it or offer a better solution. There was also an addition bug that I had to work out.
I made sure the uiwebview had the delegate set to files owner.
I changed the parent view when it pushed the view onto the form from:
[self.navigationController pushViewController:controller animated:YES];
to (the important part being the 320, i'm restricting the view to portrait):
[self.navigationController pushViewController:controller animated:YES];
controller.webView.hidden = YES;
controller.webView.frame=CGRectMake(0, 0, 320,367);
3.On the webview i load the url as i always did:
NSURL *url = [NSURL URLWithString:sUrl];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
4.In the webviewdidfinishload i now have:
if (self.interfaceOrientation ==
UIInterfaceOrientationLandscapeLeft ||
self.interfaceOrientation ==
UIInterfaceOrientationLandscapeRight) {
self.webView.frame=CGRectMake(0, 0, 480,227);
}
self.webView.hidden = NO;
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
All this would normally have solved my issue, but then i found out that the gdata url i'm getting from youtube service actually gets resolved to a 2nd url. Then i guess youtube changed their url format so it is forwarded to a 3rd url. This means that my didfinishload code was being called before the final url had loaded. To solve this i added:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if ([[[NSString stringWithFormat:#"%#",request.URL] substringWithRange:NSMakeRange(0, 26)] isEqualToString:#"http://m.youtube.com/watch"]) {
NSString *sUrl=[NSString stringWithFormat:#"%#",request.URL];
sUrl = [sUrl stringByReplacingOccurrencesOfString:#"http://m.youtube.com/watch?" withString:#"http://m.youtube.com/#/watch?"];
NSURL *url = [NSURL URLWithString:sUrl];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:requestObj];
return NO;
}
//NSLog(#"request:%#",request.URL);
return YES;
}
Which im sure could be better but basically i tell it to ignore the 2nd url, and make my own change to go to the 3rd url.

playing stream video using UIWebView issue

I'm currently developing an ipad application that will play video from wowza streamiong server.
Plainly saying, I load video into UIWebView as follows:
NSURL *videoURL = [NSURL URLWithString:#"http://fishki.tv:1935/vod/mp4:20100731194117.mp4/playlist.m3u8"];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:videoURL];
UIWebView * WView = [[UIWebView alloc] init];
WView.frame = CGRectMake(0,0,300,200);
[self.view addSubview:WView];
[WView loadRequest:requestObj];
It plays video ok (you can try yourself), BUT when i try to load another video (or even the same one) by changing videoURL and calling loadRequest method again, it plays only sound without video.
I'm starting to think that it is a bug in ipad simulator because I was unable to fix it anyhow.
I would be glad to hear any suggestions because I also was unable to find similar problem on the web. Thanks in advance.
The web view behaves erratically on Simulator. Can you try the same on a regular device? I believe it might actually be working.