GithubHelp home page GithubHelp logo

Comments (4)

jbgtmartin avatar jbgtmartin commented on June 2, 2024

Maybe it's the same issue as this one?
It seems to be fixed since iOS 15.6 at least.

The only fix I've found so far is to use version 2 of this plugin, which handles the files differently, and to wait 1 or 2 years for our users to update their iOS before switching to the last version...

from cordova-plugin-ionic-webview.

richpixel avatar richpixel commented on June 2, 2024

Thanks for your reply - I'm actually using iOS 16 on my device so I don't think this is it. I do notice there's some code in IONAssetHandler that's responsible for 'serving' the video - it appears to load the entire contents of the media file (into virtual memory which is good) and then somehow serve it through the response. This gets called repeatedly as the video is buffering/before play starts. I think this must have something to do with the issue. I suspect there must be some way to stream the data here, but I'm not sure how:

- (void)webView:(WKWebView *)webView startURLSchemeTask:(id <WKURLSchemeTask>)urlSchemeTask
{
    NSString * startPath = @"";
    NSURL * url = urlSchemeTask.request.URL;
    NSString * stringToLoad = url.path;
    NSString * scheme = url.scheme;

    if ([scheme isEqualToString:self.scheme]) {
        if ([stringToLoad hasPrefix:@"/_app_file_"]) {
            startPath = [stringToLoad stringByReplacingOccurrencesOfString:@"/_app_file_" withString:@""];
        } else {
            startPath = self.basePath ? self.basePath : @"";
            if ([stringToLoad isEqualToString:@""] || [url.pathExtension isEqualToString:@""]) {
                startPath = [startPath stringByAppendingString:@"/index.html"];
            } else {
                startPath = [startPath stringByAppendingString:stringToLoad];
            }
        }
    }
    NSError * fileError = nil;
    NSData * data = nil;
    if ([self isMediaExtension:url.pathExtension]) {
        // ENTIRE CONTENTS OF MEDIA FILE IS LOADED:
        data = [NSData dataWithContentsOfFile:startPath options:NSDataReadingMappedIfSafe error:&fileError];
    }
    if (!data || fileError) {
        data =  [[NSData alloc] initWithContentsOfFile:startPath];
    }
    NSInteger statusCode = 200;
    if (!data) {
        statusCode = 404;
    }
    NSURL * localUrl = [NSURL URLWithString:url.absoluteString];
    NSString * mimeType = [self getMimeType:url.pathExtension];
    id response = nil;
    if (data && [self isMediaExtension:url.pathExtension]) {
        response = [[NSURLResponse alloc] initWithURL:localUrl MIMEType:mimeType expectedContentLength:data.length textEncodingName:nil];
    } else {
        NSDictionary * headers = @{ @"Content-Type" : mimeType, @"Cache-Control": @"no-cache"};
        response = [[NSHTTPURLResponse alloc] initWithURL:localUrl statusCode:statusCode HTTPVersion:nil headerFields:headers];
    }
    
    [urlSchemeTask didReceiveResponse:response];
    [urlSchemeTask didReceiveData:data]; // DATA IS "SERVED" , BUT THIS GETS CALLED REPEATEDLY
    [urlSchemeTask didFinish];

}

A potential hint at a solution:
https://stackoverflow.com/questions/58217566/how-to-serve-big-files-using-wkurlschemehandler

from cordova-plugin-ionic-webview.

ghenry22 avatar ghenry22 commented on June 2, 2024

could be missing range headers when fetching from local file system, without range headers the entire file will be loaded.

from cordova-plugin-ionic-webview.

richpixel avatar richpixel commented on June 2, 2024

Thanks for the reply, that sounds promising. Do you have an idea for how to have the ionic webview accept range headers? Or supply them in the request somehow? It might actually need to happen somewhere in the code I posted.

from cordova-plugin-ionic-webview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.