2
播放音频尝试使用代码来播放mp3文件:如何在DART应用
playFile() {
audioContext = new AudioContext();
// get the audio file
return HttpRequest.request("short.mp3", responseType: "arraybuffer")
.then((HttpRequest request) {
// decode it
return audioContext.decodeAudioData(request.response)
.then((AudioBuffer buffer) {
AudioBufferSourceNode source = audioContext.createBufferSource();
source.buffer = buffer;
source.connectNode(audioContext.destination);
// play it now
source.start(audioContext.currentTime);
})
.catchError((e) {print("error occurred in decode");});
});
}
的catchError条款执行和MP3不能播放。我尝试了以上代码的不同变体,但没有运气。我似乎无法使用decodeAudioData调用从字节数组中获取AudioBuffer。任何帮助将不胜感激。谢谢。
我使用飞镖版本1.8.5 – user1848653
改变了MP3播放,OGG格式,它的工作! – user1848653