为什么AudioBufferNode中的stop方法会破坏它? [英] Why does the stop method in AudioBufferNode destroy it?

查看:165
本文介绍了为什么AudioBufferNode中的stop方法会破坏它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们知道当你在AudioBufferNode上调用#。stop()时,你不能再#。start()。为什么会出现这样的行为?

We know that when you invoke #.stop() on an AudioBufferNode, you cannot then #.start(). Why is the behavior so?

在使用WebAudio API时出现了这个问题,因为我们都会在尝试实现暂停功能时迟早发现。引起我兴趣的是,当然,我知道这是一个流,你不能简单地暂停一个流。但它为什么会被摧毁?在内部,是否没有指向数据的指针,或者数据是否只是被推送到目的地并被缓冲区遗忘?

This issue came up when playing around with WebAudio API as we all find out sooner or later when trying to implement pause functionality. What piqued my interest was, sure, I understand that it's a stream and you can't simple "pause" a stream. But why does it get destroyed? Internally, is there not a pointer to the data, or does the data simply get pushed to the destination and forgotten about by the buffer?

推荐答案

你没有在AudioBuffer上调用.stop(),你在BufferSourceNode上调用.stop() - 可以多次使用AudioBuffer。

You're not calling .stop() on an AudioBuffer, you're calling .stop() on a BufferSourceNode - the AudioBuffer can be used multiple times.

简短版本是一种优化,允许以非常轻量级的方式轻松地播放缓冲区 - 您可以围绕它构建更高级别的媒体播放器,但其本身就是BufferSourceNodes非常轻量级。声音数据本身不会被遗忘,并且可以重复使用 - 实际上,由其他BufferSourceNodes同时使用 - 因为它位于单独的AudioBuffer对象中。

The short version is it's an optimization that allows for fire-and-forget playback of buffers in a very lightweight way - you can build a higher level media player around it, but in and of itself BufferSourceNodes are very lightweight. The sound data itself is not forgotten, and can be reused - in fact, used simultaneously by other BufferSourceNodes - because it's in the separate AudioBuffer object.

这篇关于为什么AudioBufferNode中的stop方法会破坏它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆