更新后// URL到3.3.0:从cdvfile科尔多瓦视频/音频将无法播放科尔、无法播放、音频、多瓦

2023-09-12 09:12:04 作者:妳只是壹場夢i

我的科尔多瓦应用程序下载的音频文件,使其可以在设备离线播放。这是所有工作正常,直到昨天,当我升级到最新版本。

My Cordova app downloads audio files from a server and makes them available to play when the device is offline. This was all working fine until yesterday when I upgraded to the latest version.

最初,既不下载(通过文件传送插件),也不是播放(经由媒体插件)会工作。展望进一步我发现 fileSystem.root.fullPath 现在返回路径相对于应用程序的本地Web根文件夹中,但它用于返回一个完全合格的路径。科尔多瓦现在推荐使用 fileSystem.root.toURL(),而不是(http://cordova.apache.org/news/2014/02/10/plugins-release.html).这确实解决了文件传输的问题。

Initially, neither the downloading (via the file transfer plugin) nor the playing (via the media plugin) would work. Looking into it further I found that fileSystem.root.fullPath now returns a path relative to the apps local web root folder, but it used to return a fully qualified path. Cordova now recommends using fileSystem.root.toURL() instead (http://cordova.apache.org/news/2014/02/10/plugins-release.html). This did indeed fix the file transfer issue.

然而,使用新的URL方案不适用于音频文件的工作。当试图播放的文件,我得到一个错误说无法从资源'cdvfile://本地主机/永久/路径/到/文件'使用的音频文件。

However, using the new URL scheme doesn't work for audio files. When attempting to play the file I get an error saying "Cannot use audio file from resource 'cdvfile://localhost/persistent/path/to/file'".

检查科尔多瓦问题跟踪,我发现有人已经报了同一个问题的视频文件,以及(https://issues.apache.org/jira/browse/CB-6051).

Checking the Cordova issue tracker I found that someone has reported the same issue for video files as well (https://issues.apache.org/jira/browse/CB-6051).

这似乎是科尔多瓦没有更新CDVSound插件来处理新的文件名格式,但它可能仍然工作,如果我能像以前一样可以访问的完全限定路径。我已经看过了新的code和文档,但还没有找到一个方法来做到这一点。

It would seem that Cordova haven't updated the CDVSound plugin to handle the new file name format, but it might still work if I could get access to the fully qualified path as before. I have looked at the new code and docs but have not found a way to do this.

有没有人设法从文件的插件完全限定的路径?

Has anyone managed to get a fully qualified path from the file plugin?

推荐答案

我得到了它使用开发分支的文件和文件传输工作的视频。他们增加了一个功能叫做toNativeURL您需要从GitHub的项目下载zip文件中的Entry类:

I got it working for video using the dev branches for file and file-transfer. They added a function to the Entry class called toNativeURL You need to download the zip files from the github projects:

https://github.com/apache/cordova-plugin-file-transfer/tree/dev

https://github.com/apache/cordova-plugin-file/tree/dev

https://github.com/apache/cordova-plugin-media/tree/dev

然后将其安装到您的项目:

Then install them into you project:

cordova plugin rm org.apache.cordova.file-transfer
cordova plugin rm org.apache.cordova.file
cordova plugin rm org.apache.cordova.media

cordova plugin add <path_to_unzipped_dev_branch_of_file_plugin>
cordova plugin add <path_to_unzipped_dev_branch_of_file-transfer_plugin>
cordova plugin add <path_to_unzipped_dev_branch_of_media_plugin>

这是一个例子,我得到了工作:

This is an example I got working:

<!DOCTYPE html>
<!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
-->
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="format-detection" content="telephone=no" />
        <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
        <link rel="stylesheet" type="text/css" href="css/index.css" />
        <title>Hello World</title>
    </head>
    <body>
        <div id="main" class="app">
            <h1>Apache Cordova</h1>
            <div id="deviceready" class="blink">
                <p class="event listening">Connecting to Device</p>
                <p class="event received">Device is Ready</p>
            </div>
            <div id="messages">
                Loading Video...
            </div>
            <video width="320px" height="240px" controls></video>
        </div>
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
        <script type="text/javascript">
            app.initialize();

            document.addEventListener("deviceready", onDeviceReady, false);

            // device APIs are available
            //
            function onDeviceReady() {
                console.log('Requesting file system');
                window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
            }

            function gotFS(fileSystem) {
                fileSystem.root.getDirectory("vids", {create: true}, gotDir);
            }

            function gotDir(dirEntry) {
                dirEntry.getFile("video.mp4", {create: true, exclusive: false}, gotFile);
            }

            function gotFile(fileEntry) {
                var localPath = fileEntry.fullPath;
                var localUrl = fileEntry.toURL();

                console.log('Loaded local path: ' + localPath);
                console.log('Loaded local url: ' + localUrl);

                var fileTransfer = new FileTransfer();
                var uri = encodeURI('http://<url_to_video>.mp4');
                console.log('Downloading ' + uri + ' to ' + localPath);

                fileTransfer.download(
                    uri,
                    localUrl,
                    function(entry) {
                        console.log('download complete (path): ' + entry.fullPath);
                        console.log('download complete (url): ' + entry.toURL());
                        console.log('download complete (native): ' + entry.toNativeURL());
                        document.getElementById('messages').innerHTML = 
                        'Downloaded Video path: ' + entry.fullPath + '<br />'
                        + 'Downloaded Video url: ' + entry.toURL() + '<br />'
                        + 'Downloaded Video Native url: ' + entry.toNativeURL() + '<br />';
                        var videoNode = document.querySelector('video');
                        videoNode.src = entry.toNativeURL();
                    },
                    function(error) {
                        console.log('download error source ' + error.source);
                        console.log('download error target ' + error.target);
                    }
                );
            }

            function fail(error) {
                console.log('Error creating file [' + error.name + ']: ' + error.message);
            }
        </script>
    </body>
</html>

如果它与视频,它一定要带音频的工作。

If it works with video, it should definitely work with audio.

 
精彩推荐
图片推荐