[LayaAir 2.0]【官网代码】加载dom音频报错,怎么回事?

官网例子:https://ldc.layabox.com/doc/?nav=zh-as-3-4-1
其中,加载dom音频报错,怎么回事?
  1. package
  2. {
  3. import laya.events.Event;
  4. import laya.net.HttpRequest;
  5. import laya.net.Loader;
  6. import laya.utils.Browser;
  7.  
  8. public class Main
  9. {
  10. private var AudioContext:Object;
  11. private var audioContext:Object;
  12. private var analyser:Object;
  13. private var audioBufferSourceNode:Object;
  14. public function Main()
  15. {
  16. Laya.init(500,500);
  17. AudioContext =Browser.window.AudioContext || Browser.window.webkitAudioContext;
  18. audioContext = new AudioContext();
  19. analyser = audioContext.createAnalyser();
  20. analyser.fftSize = 256;
  21. Laya.stage.once(Event.CLICK,this,clickHandler);
  22.  
  23. }
  24. private function clickHandler(e:Object):void
  25. {
  26. var http:HttpRequest = new HttpRequest();
  27. http.on(Event.COMPLETE,this,completeHandler);
  28. http.send("489.mp3","","get",Loader.BUFFER);
  29. }
  30. private function completeHandler(e:Object):void
  31. {
  32. audioContext.decodeAudioData(e,decodeAudioData.bind(this));
  33. }
  34. private function decodeAudioData(buffer:Object):void
  35. {
  36. audioBufferSourceNode = audioContext.createBufferSource();
  37. audioBufferSourceNode.connect(analyser);
  38. analyser.connect(audioContext.destination);
  39. audioBufferSourceNode.buffer = buffer;
  40. audioBufferSourceNode.start(0);
  41. Laya.timer.loop(1,this,this.drawHandler);
  42. }
  43. private function drawHandler():void
  44. {
  45. Laya.stage.graphics.clear();
  46. var dataArray:Uint8Array = new Uint8Array(analyser.frequencyBinCount);
  47. analyser.getByteFrequencyData(dataArray);
  48. var step:int = Math.round(dataArray.length / 60);
  49. for (var i:int = 0; i < 40; i++) {
  50. var energy:int = (dataArray[step * i] / 256.0) * 50;
  51. for (var j:int = 0; j < energy; j++) {
  52. Laya.stage.graphics.drawLine(20 * i + 2, 200 + 4 * j,20 * (i + 1) - 2, 200 + 4 * j,"#ff0000",1);
  53. Laya.stage.graphics.drawLine(20 * i + 2, 200 - 4 * j,20 * (i + 1) - 2, 200 - 4 * j,"#ffff00",1);
  54. }
  55. Laya.stage.graphics.drawLine(20 * i + 2, 200,20 * (i + 1) - 2, 200,"#ff0000",1);
  56. }
  57. }
  58.  
  59. }
  60. }

报错:Uncaught (in promise) DOMException: Unable to decode audio data
请问怎么回事?
已邀请:

Aar0n

赞同来自:

文档里需要引的js 都下载并引入了吗? 报错是无法解码。

ohkei - as3、as2、h5

赞同来自:

audioContext.decodeAudioData(e,decodeAudioData.bind(this));
这句什么意思?就是这里报错

要回复问题请先

商务合作
商务合作