Embed video in html file loaded in UIWebView from Documents folder of application

后端 未结 5 2069
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-13 10:23

I have an html file named videoplay.html with following content




    Title         


        
5条回答
  •  隐瞒了意图╮
    2021-02-13 10:58

    After lots of struggling and R&D I found that,

    Under Simulator 3.2 and on device with iOS 4.3.3 version, using following code it is working if HTML and Video files are at the same location.

    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDir =[documentPaths objectAtIndex:0];
    NSString *pathOfHTmlFile = [documentsDir stringByAppendingPathComponent:@"videoplay.html"];
    NSString *content = [NSString stringWithContentsOfFile:pathOfHTmlFile encoding:NSUTF8StringEncoding error:nil];
    
    documentsDir = [documentsDir stringByReplacingOccurrencesOfString:@"/" withString:@"//"];
    documentsDir = [documentsDir stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
    
    NSURL *baseURL = [NSURL URLWithString:[NSString stringWithFormat:@"file:/%@//", documentsDir]];
    
    NSLog(@"Baseurl--->%@",baseURL);
    [self.webView loadHTMLString:content baseURL:baseURL];
    

    Still under Simulator 4.2 it does not work. Instead of video it shows black portion. Yet unable to find the solution for Simulator 4.2 but it works on device so I guess code is absolutely fine.

    Posting this as answer so that if any one doing the same may be useful.

提交回复
热议问题