Cordova iOS Video tag Local File Source

后端 未结 2 1260
礼貌的吻别
礼貌的吻别 2020-12-19 08:30

I have problem playing local video on iOS on my Cordova based app. At the beginning I want to stress out that this problem is happening only when I\'m using WKWebVie

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-19 09:03

    I got this working today with the following but only when deployed to my device in Release mode. When deploying the app in Debug mode to my device it would not work.

    • iOS 9.3.2
    • Cordova 4.0.0 (iOS 3.8.0)
    • Telerik WKWebView Polyfill 0.6.9

    Video list load method:

    var path = window.cordova.file.documentsDirectory, //iTunes File Sharing directory
        href = 'http://localhost:12344/Documents', //WKWebView default server url to documents
        list = [];
    function fsSuccess(dir) {
        var reader = dir.createReader();
        reader.readEntries(function (entries) {
            for (var i = 0; i < entries.length; i++) {
                list.push({ name: entries[i].name, path: href + entries[i].fullPath });
            }
        });
    }
    function fsError(error) {
        console.log('error', error)
    }
    window.resolveLocalFileSystemURL(path, fsSuccess, fsError);
    

    Video list click handler:

    var video = $('#video')[0],
        source = $('#source');
    function play(index) {
        source.attr('src', list[index].path);
        video.load();
        video.play();
    }
    

    Video player markup:

    
    

    I was banging my head on my desk a la Ren Hoek while debugging until I attempted a release buid and it worked.

提交回复
热议问题