playing stream video using UIWebView issue - iphone

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.

Related

URL load in Safari but not loading in UIWebview

I am facing an strange issue. I have a URL when I try to load that url in UIWebView it doesn't load web view remain blank but when I try to load the same url in Safari it works great and display the page. Is there any restriction for UIWebView like it can't load any specific type of widgets if webpage contain.
Thank in advance
UIWebView *webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
webView.delegate = self;
NSURL *url = [NSURL URLWithString:#"myurl"];
NSURLRequest *req = [[NSURLRequest alloc]initWithURL:url];
[self.view addSubview:webView];
[webView loadRequest:req];
Behaviour on Safari and the iOS simulator on your local machine will be the same. Both use the same proxy settings configured in System Preferences.
However - and here's the trick - each has their own distinct cookie store. To get the same behaviour you should first reset Safari and the Simulator.
This caught me out. My Safari URL worked because I had previously stored cookie values that enabled the server to fulfil my request. On the Simulator, no such cookies existed and therefore the server couldn't respond. On the surface it appeared as if the UIWebView just didn't work. However, that wasn't the case
Bottom line: reset both and try again.

Issue in playing vimeo video in webview

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.

YouTube In WebVIew - iPhone

This is very strange to me...
I have a simple WebView that loads and interacts with the user exactly like safari mobile (iPhone). Now when you visit m.youtube.com in safari, the url changes when you click on a link to something like this...
http://m.youtube.com/watch?gl=US&hl=en&client=mv-google&v=HX6SyoZ5kw8
The problem with this is I don't think that url is being used in my webview... What do I mean? The following code is used to load a url every time the user try's to click on a link, and it works, but I have a problem with Youtube...
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
NSURL *url = request.URL;
NSString *urlString = url.absoluteString;
NSLog(#"%#",urlString);
VideoURLTextBox.text = urlString;
return YES;
}
When I first start up the webview it loads m.youtube.com and NSLogs() it into my console, but when I decide to click on a video it fails to NSLog() therefore I don't think a new url is being loaded, but when you load m.youtube.com in safari and click on a video you load a url like above, so why does this not NSLog() in my iPhone application?
What your probably seeing is that the youtube video is running javascript to play the video, you'd have to intercept the javascript callbacks to see that. Here's a link to the youtube video player api, detailing the callbacks, https://developers.google.com/youtube/js_api_reference#SubscribingEvents
If you just want to embed a youtube video in an iOS application then use this.
Using the mobile YouTube site isn't great, I had lots of problems with it in the past and ended up making a UIWebView category. I came across your question and decided to throw it on github :-)
https://github.com/enigmaticflare/UIWebView-YouTube--iOS-Category--ARC-compliant-code
UIWebView+YouTube iOS category to simplify loading youtube videos.
Instructions
1) Add these files to your project
UIWebView+YouTube.h
UIWebView+YouTube.m
2) Initiate UIWebView for example
#property (strong, nonatomic) UIWebView *webView;
#synthesize webView = _webView
_webView = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,212,172];
//set the X,Y origin of CGRect to where you want the webView to appear.
_webView.delegate = self;
[_webView loadYouTubeVideoID:#"gR8dO7Cln6M"];
[self.view addSubView:_webView];
Good luck, hope this is what your looking for :)
Adam
m.youtube.com is one giant java web app, delegate methods won't get called, presumably because any loading is written directly to the DOM in the UIWebView. Ran into this problem at work, not sure of the fix but there may be a way to inject the source with a JS click handler.

Plug-in handled load UIWebview

I am developing an iPad application that plays videos from Internet Video Archive (IVA).
I can play the IVA URL in iPad-Safari. But, I am able to get it streamed in my app.
I am doing the following things to play the video:
Add an outlet to webview in the nib.
I have written the following code in my play method:
NSString *myURl = //Internet Video Archive URL; the video is in mp4 format
CGRect webFrame = [[UIScreen mainScreen] applicationFrame];
webview.frame = webFrame;
[webview setDelegate: self];
[webview loadRequest: [NSURLRequest requestWithURL: [NSURL URLWithString: myURl]]];
It gives the following error:
Error Domain=WebKitErrorDomain Code=204 UserInfo=0x1b2e30 "Plug-in
handled load"
I could play videos from other sites. Could someone help me to solve this problem?
Thanks in advance.
Regards,
Deepa

Pros and cons of MPMoviePlayerController versus launching UIWebView to stream movie

I have a client who has video content for the web in Flash format. My task is to help them show the videos in an iPhone app.
I realize that step one is to get these videos into the appropriate Quicktime format for the iPhone.
Then I'm going to have to help the client figure out how or where to host these files. If that's tricky I assume they can be hosted at YouTube.
My chief concern, though, is which approach to take to stream the video. What are the pros and cons of MPMoviePlayerController versus launching UIWebView with the URL of the stream? Is there any difference? Is one of them more or less forgiving? Is one of them a better user experience? Any gotchas I might expect to run into?
I'm assuming playing video is pretty easy on the iPhone. Is it reasonable to try both and have one available as a fallback, or would that be a waste of time? I'm trying to schedule this out a bit, so I'd love to hear real-world experiences from anyone who's done this.
EDIT: My original example in this answer initialized the webview with a frame of CGRectZero. This worked up to iOS 3.2. Starting with iOS 4 the webview must have a nonzero frame or the video won't play. I've edited my example below to reflect this change.
The accepted answer here isn't accurate. You can in fact use UIWebView to stream videos, and in some ways it's better than MPMoviePlayerController. If you tell UIWebView to request a video file (e.g. an mp4) via loadRequest:, it will open a new window and stream the video within your app. Unlike MPMoviePlayerController, the video window created by UIWebView can be rotated to landscape or portrait orientation. When the video ends, the user can close this window and return to your app.
EDIT 2: Since you can now implement a video player that rotates using MPMoviePlayerViewController, I can no longer think of a reason to use UIWebView for videos using the technique described in this answer.
Hint: Since UIWebView creates its own window to play the video, you don't even need to add the UIWebView to your view hierarchy. You can just create the UIWebView object and call loadRequest: to play the video without ever passing the object to addSubview:.
self.webView = [[[UIWebView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];
NSURL *url = [NSURL URLWithString:#"http://www.jonathancoulton.com/music/thingaweek/CodeMonkey.mp3"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
UIWebView cannot actually play videos. Navigating to a Youtube page with a UIWebview will simply launch the iPhone's Youtube App. Doing this a certain way will return control to your app after the video is played. See here: http://iphoneincubator.com/blog/tag/uiwebview
I would recommend using MPMoviePlayer Controller, as long as you are only doing simple streaming. Here's some sample code to get you started:
NSString *url = #"http://www.example.com/path/to/movie.mp4";
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc]
initWithContentURL:[NSURL URLWithString:url]];
[moviePlayer play];