读取本地声音文件并在html5画布中获取波形
Read in local sound file and get the waveform in html5 canvas
我目前正在尝试从用户提供的声音文件中获取波形。现在,从服务器加载的默认歌曲将正确播放和显示,但当用户选择声音文件时,它将播放声音,而不是波形。
// Create a new instance of an audio object and adjust some of its properties
var audio = new Audio();
audio.src = 'song.mp3';
audio.controls = true;
audio.loop = false;
audio.autoplay = true;
// Establish all variables that your Analyser will use
var source, context, analyser, fbc_array, bars, bar_x, bar_width, bar_height;
function initMp3Player(){
document.getElementById('audio_box').appendChild(audio);
context = new webkitAudioContext(); // AudioContext object instance
analyser = context.createAnalyser(); // AnalyserNode method
// Re-route audio playback into the processing graph of the AudioContext
source = context.createMediaElementSource(audio);
source.connect(analyser);
analyser.connect(context.destination);
}
function init() {
canvas = document.getElementById('canvas');
ctx = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
ctx.fillStyle = "rgb(0,0,0)";
ctx.fillRect(0, 0, canvas.width, canvas.height);
//add load file ability
document.getElementById('audio_file').onchange = function(){
audio = new Audio();
var files = this.files;
var file = URL.createObjectURL(files[0]);
audio.src = file;
initMp3Player();
};
initMp3Player();
}
我不应该再次调用initMp3Player()。
相关文章:
- html5视频中的Youtube类型注释
- 如何在运行时在HTML5画布中绘制正方形
- 正在检测html5手机中的抖动
- Unicode字符未在HTML5画布中正确呈现
- 通过phonegap中的电子邮件发送存储在html5 localStorage中的信息
- 如何在html5画布中绘制圆形作为单独的画布
- 重定向到具有轨道的html5模式中的正确角度路线
- html5画布中的套索工具
- 什么'是在HTML5画布中创建关键事件的最佳方式
- HTML5模式中的$location需要<基本>
- 在HTML5画布中,是否可以围绕旋转对象旋转对象
- 如何将自定义字体轻松地放入HTML5画布中
- 如何在MVC5中运行时在HTML5 Canvas中显示图像
- 如何在HTML5视频中获得寻找事件的起点
- 在Javascript HTML5+Canvas中处理精灵鼠标点击的最佳方式
- 使用模式在 HTML5/JS 中绘制图像
- 如何在HTML5 / javascript中查找十六进制值的特定位或数字
- 如何在html5/JS中只预加载音频文件的一部分
- HTML5游戏中最有效的视差方式
- 存储在HTML5存储中的引导崩溃的当前状态