简体   繁体   English

WebAudio 停止后不播放(0)

[英]WebAudio not playing after stop(0)

I'm writing something like a web-audio-editor, and I think I'm close to finishing the basics.我正在写一个类似网络音频编辑器的东西,我想我已经接近完成基础知识了。 I can play and stop an audiofile, but when I try to call the play method again it just won't work, even though the parameters havn't changed.我可以播放和停止一个音频文件,但是当我尝试再次调用播放方法时它就不起作用了,即使参数没有改变。

I'd be glad to see someone look into my problem as I cannot see why it doesn't work when similar code in other projects does.我很高兴看到有人研究我的问题,因为我不明白为什么当其他项目中的类似代码起作用时它不起作用。 Unfortunately I cannot create a jsfiddle, because I would need to load an external mp3-file and it seems I'm not allowed to do that.不幸的是,我无法创建 jsfiddle,因为我需要加载外部 mp3 文件,而且我似乎不允许这样做。 But I have pasted the javascript here and the corresponding html file here .但是我这里粘贴了javascript和对应的html文件。

All you need is a server you can upload the files to and a mp3 on it.您所需要的只是一个可以将文件上传到的服务器和一个 mp3。 Alternately you could use this link , but I will delete the files eventually.或者,您可以使用此链接,但我最终会删除这些文件。

You can't call start() on an AudioBufferSourceNode more than once. 您不能AudioBufferSourceNodeAudioBufferSourceNode上调用start() They're one-time-use only. 它们只是一次性使用。

Really the only way to do this is to create a new AudioBufferSourceNode from the underlying AudioBuffer every time you need to start playback. 实际上,唯一的方法是每次需要开始播放时从底层的AudioBuffer创建一个新的AudioBufferSourceNode

您也可以让它保持运行并简单地将其从增益节点断开,振荡器可能只是空闲/静默地产生波形。

To avoid creating a new AudioBufferSourceNode , you can simply use the playbackRate like this:为避免创建新的AudioBufferSourceNode ,您可以像这样简单地使用playbackRate

source.playbackRate.value = 0; to pause.暂停。

source.playbackRate.value = 1; to play.玩。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM