Adding youtube video to my application - iphone

This is how i added a youtube video to my project; I have added these to the viewDidLoad Function
UIWebView *web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 480, 300)];
NSString *html = #"<html><head> .........."; // its too long so i cut it short
[webView loadHTMLString:html baseURL:[NSURL URLWithString:#"http://www.youtube.com/embed/vLBKOcUbHR0"]];
[self.view addSubview:web];
The view what i see is;
And what i want is some thing like this
If you look closer, you will see a ToolBar and a DOne button, and also a UIActivityIndicator in the second image, and none of these are displaying in mine. How can i solve this ?

That's not really how you use baseURL. The Base URL is what relative links will be relative to if there are links in the HTML - mapping it to youtube probably won't help at all.
Instead, just copy the embed code from youtube, which looks like this:
<iframe width="420" height="315" src="http://www.youtube.com/embed/2WNrx2jq184" frameborder="0" allowfullscreen></iframe>
Copy the URL from the iframe and open it directly in your web view, like this:
NSURL *URL = [NSURL URLWithString:#"http://www.youtube.com/embed/2WNrx2jq184"];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
[webView loadRequest:request];
That should work.

Related

Show multiple PDF with one UIwebView

I hope someone can help me.
In one view of the app I've got a UIWebView where I'm showing the PDF file. I need to show 3 different PDF (a.pdf, b.pdf, c.pdf) in the same UIWebView. I know how to show one.
CGRect frame2 = CGRectMake(20, 25, 280, 350);
testWebView = [[UIWebView alloc] initWithFrame:frame2];
NSString *path = [[NSBundle mainBundle] pathForResource:#"a" ofType:#"doc"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[apneaWebView loadRequest:request];
[apneaWebView setScalesPageToFit:YES];
[self.view addSubview:testWebView];
But if are 3 different PDf what to do.
Thanks for any help.
Look at that: Can we display many pdf in a UIWebview?
You can only display a pdf in a UIWebView. You can try to create 3 different UIWebViews for every PDF or try to merge them.

I want to play a quicktime movie in my app

I would like to play a quicktime movie in my app, can it be possible in webview or in any other view, my only resource is my quicktime link.
I already used a little trick to play audio files from URL in QuickTime. I guess it can work for movies files too. Here is my code :
NSString *url = #"http://my_url.com/my_movie_path/";
UIWebView* tempAudioPlayer = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
[tempAudioPlayer loadHTMLString:[NSString stringWithFormat:#"<iframe frameborder=\"0\" width=\"0\" height=\"0\" src=\"%#\"></iframe>", url] baseURL:nil];
[self addSubview:tempAudioPlayer];
I first create a UIWebView which will not be displayed. Then I loadHTMLString a <iframe> in it, with the URL of my file as the src value. And I add it to my view. Quicktime appears immediately.
NSString *url = "http://my_url.com/my_movie_path/AAA.mov";
UIWebView *tempAudioPlayer;
[tempAudioPlayer loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];

Creating a WebView programmatically and displaying NSStrings inside the view

I have created a WebView programmatically. This works perfect. The code is below.
What I need to try and do now is inject NSStrings into it. I have an array of 30 strings. 15 Headings and 15 body-texts.
Is it possible to get these displayed inside the WebView? I'm guessing I need to change them into a HTML, i may be reformat them all into 1 long NSString with HTML-tags and linebreaks and newling-tags maybe?
Anybody able to help me with some pointers/code snippets to get me on the right track and moving the the correct direction please?
- (void) initUIWebView
{
aWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 290)];//init and
create the UIWebView
aWebView.autoresizesSubviews = YES;
aWebView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
[aWebView setDelegate:self];
NSString *urlAddress = #"http://www.google.com"; // test view is working with url to webpage
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[aWebView loadRequest:requestObj];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 300)];
[[self view] addSubview:aWebView];
}
Thanks
-Code
Instead of using the loadRequest method you will have to use the loadHTMLString method of UIWebView
The following code might help you in displaying the NSString in UIWebView
NSString *html = #"<html><head></head><body>The Meaning of Life<p>...really is <b>42</b>!</p></body></html>";
[webView loadHTMLString:html baseURL:nil];
Hope this will resolve your issue...

How to embbed video on uiview or uiwebview

There are some apps in the app store that have a video stream without using mpvideo and they are embbeded on the uiview or uiwebview.
How is this implementation done? Any help is great thanks.
Probably with the standard HTML5 <video> tag. It allows you to play a video file that is local or remote. Or even a live stream. Check Apple's Safari Dev Center for all details.
You can try to load the HTML code into the webview itself with loadHTMLString:
The method is part of UIWebView and looks something like this:
[self.webview loadHTMLString:(NSString *)_some_string baseURL:nil]
You can store a basic html page with the embed code for the video in the _some_string variable and it will load up that page with the embed code.
NSString *html = #"\
<html>\
<head></head>\
<embed code for video here>\
</body></html>";
[self.webView loadHTMLString:html baseURL:nil];
This is a pretty complicated solution due to the way Apple has videos setup.
Create an HTML file with a basic HTML5 video player, with source="video/you/want". Be sure to add webkit-playsinline to the video.
<video width=“320” height=“240” webkit-playsinline><source src=“sample_iPod.m4v”/></video>
Add this player.html as a resource to your Xcode project.
Create a UIWebView, hook it up in the Storyboard editor, and then do the following in ViewDidLoad:
//set the webView delegate - hook up in Storyboard as well!
self.webView.delegate = self;
//initialize our HTML path - the file is player.html in our project
NSString *htmlPath = [[NSBundle mainBundle] pathForResource:#”player” ofType:#”html”];
//encode the path
NSString *escapedPath = [htmlPath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//webview needs NSURL, so let’s make one
NSURL *url = [NSURL URLWithString:escapedPath];
//load the request in the webview
[self.webView loadRequest:[NSURLRequest requestWithURL:url]];
Finally, the key step, be sure to flag the view to allow inline playback.
//flag the webview to play inline
self.webView.allowsInlineMediaPlayback = YES;
I wrote a post with more details here.
Can you try this one.
- (void)viewDidLoad {
[super viewDidLoad];
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.businessfactors.de/bfcms/images/stories/videos/defaultscreenvideos.mp4\" type=\"application/x-shockwave-mp4\" \
width=\"%0.0f\" height=\"%0.0f\"></embed>\
</body></html>";
webView = [[UIWebView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 412.0)];
[webView setOpaque:NO];
NSString *html = [NSString stringWithFormat:embedHTML, webView.frame.size.width, webView.frame.size.height];
[webView loadHTMLString:html baseURL:nil];
[self.view addSubview:webView];
}

iPhone SDK: Preferences

I wanted an entire page of text(multiple lines) in my settings similar to the one on iphone:
settings->general settings->About->Legal
I have not been able to do so. I tried entering title in PSGroupSpecifier, it gives me multiple lines but with a gray background. i wanted a white background.
Any help would be highly appreciated.
Thanks in advance
Use a UIWebView and store your page as a HTML file in your resources.
// Create the UIWebView
UIWebView *webView = [[[UIWebView alloc] initWithFrame:self.view.frame] autorelease];
// Add the UIWebView to our view
[self.view addSubview:webView];
// Load the HTML document from resources
NSString *pagePath = [[NSBundle mainBundle] pathForResource:#"legal" ofType:#"html"];
NSURL *pageURL = [NSURL fileURLWithPath:pagePath];
NSURLRequest *pageReq = [NSURLRequest requestWithURL:pageURL];
[webView loadRequest:pageReq];