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 声音文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
                问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
                Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                quot;Each child in an array should have a unique key propquot; only on first time render of page(“数组中的每个孩子都应该有一个唯一的 key prop仅在第一次呈现页面时)
                CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                Ordinals in words javascript(javascript中的序数)
              • <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>