下面这段JS代码在MS edge和firefox上都工作正常,就在chrome下报unsupported source。运行环境是win10,请帮看一下是代码问题还是chrome对html5和web audio api支持的问题。谢谢。
-------------------------------------------------------------------
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Document</title>
<style type="text/css">
#cas{
position: absolute;
left:0;top:0;bottom: 0;right: 0;
margin: auto;
border: 1px solid;
}
</style>
</head>
<body>
<input type="file" name="" id="music" />
<canvas id="cas" width="1000" height="540"></canvas>
<script type="text/javascript" charset="utf-8">
var music = document.getElementById("music"),canvas = document.getElementById("cas"),ctx=canvas.getContext("2d");
window.AudioContext= window.AudioContext||window.webkitAudioContext||window.mozAudioContext;
window.RAF = (function(){
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function (callback) {window.setTimeout(callback, 1000 / 60); };
})();
var AC = new AudioContext();
music.onchange = function(){
if(music.files.length!==0){
var audioElement = document.createElement('audio');
audioElement.loop = true;
audioElement.crossOrigin = 'anonymous';
audioElement.src = music.files[0];
audioElementSource = AC.createMediaElementSource(audioElement);
audioElementSource.connect(AC.destination);
//audioElement.load();
audioElement.play();
}
}
</script>
</body>
</html>
--
FROM 111.204.125.*