【问题标题】:Playing parts of an audio file in WebAudio在 WebAudio 中播放部分音频文件
【发布时间】:2013-06-19 19:24:56
【问题描述】:

我没有加载 9 个具有不同音效的不同音频文件,而是将我的音效编译到一个 .ogg 文件中,并且每种音效都有不同的开始和停止时间。但是,我在 WebAudio API 中看不到任何处理此问题的方法。我确定有。有人知道吗?

【问题讨论】:

  • 您能否更彻底地解释一下您想要完成的任务?您是否要同时播放所有这些声音?

标签: html google-chrome webkit web-audio-api


【解决方案1】:

这里是怎么做的。

var context = new AudioContext();
var mainNode = context.createGainNode(0);
mainNode.connect(context.destination);

function play_sound(sound, start, length) { 
    var source = context.createBufferSource();
    source.buffer = get_buffer(sound); // assume get_buffer gets a file that has already been
    source.connect(mainNode);          // loaded and decoded with context.decodeAudioData()
    source.start(0, start, length);
}

// lets say I want to play a 0.2 second sound effect in sfx.ogg starting at 0.5 seconds.
play_sound('sfx.ogg', 0.5, 0.2);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多