尝试使用代码播放mp3文件:
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无法播放。我尝试了上述代码的其他变体,但没有运气。我只是似乎无法使用解码音频数据调用从字节数组获取AudioBuffer。任何帮助将不胜感激。谢谢。
最佳答案
必须使用.ogg格式。 mp3无法正常工作!
关于dart - 如何在Dart应用程序中播放音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29482107/