2015-04-07 67 views
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。任何帮助将不胜感激。谢谢。

+0

我使用飞镖版本1.8.5 – user1848653

+0

改变了MP3播放,OGG格式,它的工作! – user1848653

回答

0

必须使用.ogg格式。 MP3不起作用!

+0

.mp3可以正常工作,但您需要额外的浏览器插件。 – Robert

相关问题