Dart web audio noteOn内部错误

时间:2014-08-21 19:48:21

标签: audio dart dart-html

我正试图让dart播放音频,但每次我尝试播放音频时都会出现以下错误:

Internal error: 'dart:_blink': error: line 248: native function 'AudioBufferSourceNode_noteOn_Callback_RESOLVER_STRING_1_double' (2 arguments) cannot be found
Native_AudioBufferSourceNode_noteOn_Callback(mthis, when) native "AudioBufferSourceNode_noteOn_Callback_RESOLVER_STRING_1_double";

这是我的音频课程:

class Audio {

  static List<Audio> _loadQueue = new List<Audio>();

  String _url;
  bool loaded = false;
  AudioBufferSourceNode _source;

  Audio(this._url) {
    if (audioContext == null) {
      _loadQueue.add(this);
    }
    else {
      load();
    }
  }

  void load() {
    print("Loading sound: " + _url);
    HttpRequest req = new HttpRequest();
    req.open("GET", _url);
    req.responseType = "arraybuffer";
    req.onLoad.listen((e) {
      _source = audioContext.createBufferSource();
      print("Found sound: " + _url + ". Decoding...");
      audioContext.decodeAudioData(req.response).then((buffer) {
        _source.buffer = buffer;
        _source.connectNode(gainNode);
        _source.connectNode(audioContext.destination);
        loaded = true;
      });
    });

    req.send();
  }

  void play() {
    if (!loaded) { return; }
    _source.noteOn(0);
  }

  void stop() {
    if (!loaded) return;
    _source.noteOff(0);
  }

  static void loadAll() {

    _loadQueue.forEach((e) {e.load();});
  }
}

音频上下文和增益节点在另一个类中创建,如下所示:

audioContext = new AudioContext();
gainNode = audioContext.createGain();
gainNode.connectNode(audioContext.destination);

Audio.loadAll();

我不知道问题是什么,特别是因为它说它是内部的,并且它缺少参数,但noteOn函数只接受一个参数。

1 个答案:

答案 0 :(得分:1)