In my app IOS I must play videos that reside on server. When I call the URL (http://www.example.com/example/?q=courses/9/module/148) from computer's browser it returns file (.flv) and the browser asked me if I have to save or open the file.
How to do to play video in IOS app'view by URL address?
Is it possible by UIWebView?
Thanks
First create an String with your html embed code, here is an example:
NSString *htmlString = [NSString stringWithFormat: #"<iframe src=\"http://myvideo.com" width=\"305\" height=\"150\" frameborder=\"0\" scrolling=\"no\"> </iframe>"];
Then load the address into your web view
[self.myWebView loadHTMLString:htmlString baseURL:[NSURL URLWithString:#"http://whicheveraddresyouwant.com"]];
Related
I want to open .csv link in the UIWebView. I am getting link some .csv links from the web how to open that link in the UIWebView. I am using the below code
NSString *urlString = #"https://xoxoengage-images-test.s3.amazonaws.com/image/clients/gxoxo/annoucement/XXXXdetails201805021526899124.csv";
NSURL *url = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];//[NSURL URLWithString:urlString];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[_webviewobj loadRequest:urlRequest];
but the result is shown in the below image, help me out to sort this issue.
The UIWebView doesn't support the CSV format natively.
See this: File Formats Supported by UIWebView
If your server returns "text/plain" (or you have this file as ".txt") you'll see its raw text in the web view.
If you want a grid table view, then you need to convert csv to to one of the supported formats. The obvious choice would be HTML.
If you can convert on the server side - that's better, otherwise download the csv file, parse it line by line, and output as HTML. Load the HTML into the web view. loadHTMLString is what you could use.
Also with UIWebView this can be done sort of transparently using a custom NSURLProtocol.
This might be helpful: Where can I find a CSV to NSArray parser for Objective-C?
I am working on an app in which i have to display videos comes from JSON server some of them are youtube video and some are from other resources.
My problem is when i want to play video the videos which are from youtube link are playing perfectly but the other videos are not playing.
i imported <AVFoundation/AVFoundation.h>, <AVKit/AVKit.h>, MediaPlayer/MediaPlayer.h files also i imported YTPlayerView Files
I am using following code in UIWebView
[self.webvw setAllowsInlineMediaPlayback:YES];
[self.webvw setMediaPlaybackRequiresUserAction:NO];
NSString* embedHTML = [NSString stringWithFormat:#"%#",videoStr];
[self.webvw loadHTMLString:embedHTML baseURL:[[NSBundle mainBundle] resourceURL]];
The other video format is look like as:
"embed_code": "<object width="430" height="344"><embed width="430" height="344" type="application/x-shockwave-flash" wmode="transparent" src="http://xxxxxxx.xxxxxx/static/jscript/player/flowplayer/flowplayer.swf?config={'clip':{'baseUrl': 'http://myconnect.media/file/video/','url': '2017/02/3d045f0f240bfb73305f77c3da4d9218.flv','autoBuffering': true,'autoPlay': false}}"></embed></object>"
I have many url's like this:
https://www.youtube.com/watch?v=81_2Xb0XB_E&feature=youtube_gdata
I want to see in my app only the video, rather than a youtube page.
How can I go about this?
So far I have tried:
urlValue = [urlValue stringByReplacingOccurrencesOfString:#"watch?v="
withString:#"v/"];
urlValue = [urlValue stringByReplacingOccurrencesOfString:#"&feature"
withString:#"?version=3&f=playlists&app"];
This is the final url :
https://www.youtube.com/v/81_2Xb0XB_E?version=3&f=playlists&app=youtube_gdata_player
And this is how I load it:
NSString *videoHTML = [NSString stringWithFormat:#"<iframe type=\"text/html\" width=\"305\" height=\"180\" src=\"%#\" frameborder=\"0\"></iframe>", urlValue];
For some of them it's ok, I can watch it, but for others, like this url I cant watch. ("Watch this video on youtube . Playback on other website has been disabled by the video owner").
Any idea how can I improve my code? or if it's because of url?
Here is an example of url which is working:
http: //www.youtube.com/v/9M3wwddDec4?version=3&f=playlists&app=youtube_gdata_player
Give this a try HCYoutubeParser
I want to load a web site on a UIWebView which is not under my control and edit/add certain UI changes (Some texts, images, etc) to it. Can I do this within my iOS source code? I can't change the hosted html contents since them not under my control.
If this cannot doable within iOS source code, please advice me the correct way to achieve this.
Load the webpage into an NSString, make any modifications and then put the html into the UIWebView.
NSURL *url = [NSURL URLWithString:#"http://example.com/"];
NSString *page = [NSString stringWithContentsOfURL:url usedEncoding:nil error:nil];
/* Make changes to page here */
[self.webView loadHTMLString:page baseURL:nil];
I'd get the dom with JavaScript, manipulate, then inject back with JavaScript.
See stringByEvaluatingJavaScriptFromString:.
You can write your own full featured, minified JavaScript, then pass into using this method.
// Change body color of any HTML content inside a UIWebView.
NSString *javaScript = #"document.getElementByTagName('body').backgroundColor = '#888';";
[webView stringByEvaluatingJavaScriptFromString:javaScript];
I'm trying to display MS office files(word,powerpoint,excel) using UIWebview some of the files have macros enable UIWebview is unable to display these files any idea why this happen? is there a way to make UIWebview render these files?.
Note: I do not want the macros to work if i can display the content of the file that will be enough.
I know this is old, but I ran into it today. It looks UIWebView will NOT open macro-enabled Office files directly. For example, the following code fails -
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:filePath]]];
The code above fails ONLY for macro-enabled Office files - it works just fine for .docx, .pptx, .rtf, .pdf, .txt, etc. files. However, if we pull the file into NSData and then provide the mime type explicitly to UIWebView, the file will open. The code below will open these macro-enabled Office files -
// this will open a .pptm file - replace mime type as necessary for other macro-enabled file types
NSData* fileData = [NSData dataWithContentsOfFile:filePath];
[webView loadData:fileData MIMEType:#"application/vnd.ms-powerpoint.presentation.macroEnabled.12" textEncodingName:nil baseURL:nil];
Tested with .pptm, .ppsm, .potm, .docm, .xlsm