cordova Ionic youtube视频下载

时间:2016-02-23 12:31:29

标签: cordova video download youtube

我在使用cordova下载视频时出现问题,而且离线框架视频是下载的,但是只下载了56或60 kb的数据(不确定是否是其视频)但是它没有在移动设备中播放(不支持的视频错误)。一个帮助。



<!DOCTYPE html>
<html>
    <head>
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">      
  <title>Hello World</title>
    </head>
    <body>
        <script src="cordova.js"></script>
        
        <a href="#" onclick="downloadvid();">Download Video</a>
        
        <script>
            document.addEventListener("deviceready", onDeviceReady, false);
            function onDeviceReady() {
                alert("Got deviceready");
            }
        
            function downloadvid() {
                var fileTransfer = new FileTransfer();
//                var inputUri = encodeURI("https://www.youtube.com/watch?v=01x3rDcNMpw");
                var inputUri = "https://www.youtube.com/watch?v=01x3rDcNMpw";
                var outputPath = cordova.file.externalDataDirectory + "sample.mp4";
               
                alert("Starting download to " + outputPath);
                fileTransfer.download(
                      inputUri,
                      outputPath,
                    function (entry) {
                        alert("Download complete: " + entry.fullPath + ", URL=" + entry.toURL());
                        cordova.plugins.fileOpener2.open(
                            entry.toURL(), 
                            'video/*',
                            {
                                error: function (e) {
                                    alert('fileOpener2 error status: ' + e.status + ' - Error message: ' + e.message);
                                },
                                success: function () {
                                    alert('fileOpener2 file opened successfully');
                                }
                            }
                        );
                    },
                    function (error) {
                        alert("download error: source=" + error.source+ ", target=" + error.target + ", error code=" + error.code);
                    });
            }
        </script>
    </body>
</html>
&#13;
&#13;
&#13;

0 个答案:

没有答案