1. <legend id='w9PDD'><style id='w9PDD'><dir id='w9PDD'><q id='w9PDD'></q></dir></style></legend>

  2. <small id='w9PDD'></small><noframes id='w9PDD'>

    <i id='w9PDD'><tr id='w9PDD'><dt id='w9PDD'><q id='w9PDD'><span id='w9PDD'><b id='w9PDD'><form id='w9PDD'><ins id='w9PDD'></ins><ul id='w9PDD'></ul><sub id='w9PDD'></sub></form><legend id='w9PDD'></legend><bdo id='w9PDD'><pre id='w9PDD'><center id='w9PDD'></center></pre></bdo></b><th id='w9PDD'></th></span></q></dt></tr></i><div id='w9PDD'><tfoot id='w9PDD'></tfoot><dl id='w9PDD'><fieldset id='w9PDD'></fieldset></dl></div>

      • <bdo id='w9PDD'></bdo><ul id='w9PDD'></ul>
      <tfoot id='w9PDD'></tfoot>

      使用 javascript 播放以 base64 编码的 .wav 声音文件

      play .wav sound file encoded in base64 with javascript(使用 javascript 播放以 base64 编码的 .wav 声音文件)

            <tbody id='KmFbM'></tbody>

            <bdo id='KmFbM'></bdo><ul id='KmFbM'></ul>
              <legend id='KmFbM'><style id='KmFbM'><dir id='KmFbM'><q id='KmFbM'></q></dir></style></legend>

                <small id='KmFbM'></small><noframes id='KmFbM'>

                <i id='KmFbM'><tr id='KmFbM'><dt id='KmFbM'><q id='KmFbM'><span id='KmFbM'><b id='KmFbM'><form id='KmFbM'><ins id='KmFbM'></ins><ul id='KmFbM'></ul><sub id='KmFbM'></sub></form><legend id='KmFbM'></legend><bdo id='KmFbM'><pre id='KmFbM'><center id='KmFbM'></center></pre></bdo></b><th id='KmFbM'></th></span></q></dt></tr></i><div id='KmFbM'><tfoot id='KmFbM'></tfoot><dl id='KmFbM'><fieldset id='KmFbM'></fieldset></dl></div>
                <tfoot id='KmFbM'></tfoot>
                本文介绍了使用 javascript 播放以 base64 编码的 .wav 声音文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我可以通过以下方式使用 javascript 播放声音,

                Am able to play sound with javascript through the following,

                    var snd = new Audio('sound.wav');
                    snd.play();
                

                这会播放所需的声音,但有时加载速度很慢,甚至可能根本不加载所以我用 base 64 对声音进行了编码,并尝试以这种方式播放.

                This plays the required sound but sometimes it loads slowly or might not even load at all so i encoded the sound in base 64 and tried to play it this way.

                      var splash = {
                prefix: "data:audio/wav;base64,",
                sound: [ "*base64 string here*" ] };
                
                    var snd = new Audio(splash); 
                    snd.play();
                

                但声音不播放,有什么办法吗?

                but the sound does not play, is there a way around it ?

                推荐答案

                这看起来不像为 HTMLAudioElement/<audio>.

                That doesn't look like the correct way to use the Audio constructor for HTMLAudioElement / <audio>.

                微调

                var snd = new Audio("data:audio/wav;base64," + base64string);
                snd.play();
                

                如果它在控制台中有效但在脚本中无效,则可能会被垃圾收集,在这种情况下,它的范围将保持不变

                If it works in console but not in script, it may be getting garbage collected, in which case scope it so it will stay

                var Sound = (function () {
                    var df = document.createDocumentFragment();
                    return function Sound(src) {
                        var snd = new Audio(src);
                        df.appendChild(snd); // keep in fragment until finished playing
                        snd.addEventListener('ended', function () {df.removeChild(snd);});
                        snd.play();
                        return snd;
                    }
                }());
                // then do it
                var snd = Sound("data:audio/wav;base64," + base64string);
                

                这篇关于使用 javascript 播放以 base64 编码的 .wav 声音文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Fetch multiple links inside foreach loop(在 foreach 循环中获取多个链接)
                Backbone Fetch Request is OPTIONS method(Backbone Fetch Request 是 OPTIONS 方法)
                Fetch API leaks memory in Chrome(Fetch API 在 Chrome 中泄漏内存)
                How can I download and save a file using the Fetch API? (Node.js)(如何使用 Fetch API 下载和保存文件?(Node.js))
                Send blob data to node using fetch, multer, express(使用 fetch、multer、express 将 blob 数据发送到节点)
                Sending a custom User-Agent string along with my headers (fetch)(发送自定义用户代理字符串以及我的标头(获取))
              • <legend id='wtx4q'><style id='wtx4q'><dir id='wtx4q'><q id='wtx4q'></q></dir></style></legend>
                    • <bdo id='wtx4q'></bdo><ul id='wtx4q'></ul>
                    • <small id='wtx4q'></small><noframes id='wtx4q'>

                        <tbody id='wtx4q'></tbody>

                    • <tfoot id='wtx4q'></tfoot>

                        <i id='wtx4q'><tr id='wtx4q'><dt id='wtx4q'><q id='wtx4q'><span id='wtx4q'><b id='wtx4q'><form id='wtx4q'><ins id='wtx4q'></ins><ul id='wtx4q'></ul><sub id='wtx4q'></sub></form><legend id='wtx4q'></legend><bdo id='wtx4q'><pre id='wtx4q'><center id='wtx4q'></center></pre></bdo></b><th id='wtx4q'></th></span></q></dt></tr></i><div id='wtx4q'><tfoot id='wtx4q'></tfoot><dl id='wtx4q'><fieldset id='wtx4q'></fieldset></dl></div>