1

我想将创建的地址传递window.URL.createObjectURL(file)给 dancer.js 但我得到了GET blob:http%3A//localhost/b847c5cd-aaa7-4ce0-8ff8-c13c6fc3505a.mp3 404 (Not Found).

我设法使用通过文件输入选择的文件创建音频元素,但 dancer.js 根本找不到文件......有什么想法吗?(下面我如何传递 ObjectURL)

    $(document).ready(function(){
    $("#submit").click(function(){
        var file = document.getElementById("file").files[0];
        $('body').append('<audio id="audio" controls="controls"></audio>');
        $('#audio').append('<source src='+window.URL.createObjectURL(file)+' type=audio/mpeg />')
        $('body').append('<a href='+window.URL.createObjectURL(file)+'>link</a>')
        dancer(window.URL.createObjectURL(file));
    })
})
4

1 回答 1

4

查看dancer.js 自述文件,看起来该load方法将采用对<audio>元素的引用或指定源的配置对象:{scr: varHoldingFileURL}. 由于您已经<audio>为您的文件创建了一个元素,我只需将其传递给舞者:

$(document).ready(function() {
    var dancer = new Dancer(),
        fileURL;

    $("#submit").click(function(){
            var audioElement,
                file = document.getElementById("file").files[0];

            fileURL = window.URL.createObjectURL(file);

            // remove any preexisting instances of the audio tag
            $('#audio').remove();

            // Revoke any previously used file URL so it doesn't
            // take up memory anymore.
            window.URL.revokeObjectURL(fileURL);

            $('body').append('<audio id="audio" controls="controls"></audio>');
            $('#audio').append('<source src='+ fileURL +' type=audio/mpeg />')
            $('body').append('<a href=' + fileURL +'>link</a>')

            // get a reference to the audio element we created
            audioElement = $('#audio')[0];

            dancer.load(audioElement);
    })
});
于 2013-02-21T22:13:40.377 回答