Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIWebView load local video data

I am trying to load a Video in UIWebView. Video is stored in local file system. Here is the code snippet I am using for loading the video.

{
   NSString* filePAth = [[NSBundle mainBundle] pathForResource:@"sample_iPod" ofType:@"m4v"];
   NSLog(@"%@",filePAth);
   NSData* data = [NSData dataWithContentsOfFile:filePAth];
   [_webView loadData:data MIMEType:@"video/x-m4v" textEncodingName:@"UTF-8" baseURL:nil];
}

This is the error I get in console:

Error in Webview loading: Error Domain=WebKitErrorDomain Code=204 "Plug-in handled load" UserInfo=0x1f8b3c70 {NSErrorFailingURLStringKey=applewebdata://3F0047AD-E6CF-4EAD-A4C3-DA6E1C0BD603, WebKitErrorMIMETypeKey=video/x-m4v, NSErrorFailingURLKey=applewebdata://3F0047AD-E6CF-4EAD-A4C3-DA6E1C0BD603, NSLocalizedDescription=Plug-in handled load}

However, The same code works for loading all other file type for eg: PNG, DOC et.c.

Please help...!!!

like image 299
Rishabh Tayal Avatar asked Oct 12 '12 14:10

Rishabh Tayal


People also ask

Which method is used to load the content into a Uiwebview?

Use the loadHTMLString(_:baseURL:) method to begin loading local HTML files or the loadRequest(_:) method to begin loading web content. Use the stopLoading() method to stop loading, and the isLoading property to find out if a web view is in the process of loading.

What is WKWebView?

Overview. A WKWebView object is a platform-native view that you use to incorporate web content seamlessly into your app's UI. A web view supports a full web-browsing experience, and presents HTML, CSS, and JavaScript content alongside your app's native views.

How do I upgrade Uiwebview to WKWebView?

Step-1: Firstly, create a new project with a Single View App. Step-2: Then, open “Main. storyboard” and on your ViewController's view drag “Webkit View”. Select a WKWebView and place it on your view of a view controller.


1 Answers

You should load local videos and other videos whenever possible with MPMoviePlayerController - (Documentation) - If playing the video is all you need and want and you are developing a native app.

like image 162
Daniel Avatar answered Oct 01 '22 21:10

Daniel