add analyzer setup
This commit is contained in:
parent
912da7c28b
commit
dadf192aef
|
@ -1,8 +1,10 @@
|
||||||
var player;
|
var player;
|
||||||
var pos_int;
|
var pos_int;
|
||||||
|
var analyser;
|
||||||
|
var audio_data;
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
player = document.getElementById('player');
|
player = document.querySelector('#player');
|
||||||
|
|
||||||
player.addEventListener("ended", nextTrack);
|
player.addEventListener("ended", nextTrack);
|
||||||
|
|
||||||
|
@ -13,6 +15,8 @@ function init() {
|
||||||
navigator.mediaSession.setActionHandler('nexttrack', nextTrack);
|
navigator.mediaSession.setActionHandler('nexttrack', nextTrack);
|
||||||
|
|
||||||
pos_int = setInterval(update_position, 300);
|
pos_int = setInterval(update_position, 300);
|
||||||
|
|
||||||
|
init_analyzer();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function get_rand_track() {
|
async function get_rand_track() {
|
||||||
|
@ -77,4 +81,17 @@ function update_position() {
|
||||||
playbackRate: player.playbackRate,
|
playbackRate: player.playbackRate,
|
||||||
position: parseInt(player.currentTime)
|
position: parseInt(player.currentTime)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
analyser.getByteTimeDomainData(audio_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
function init_analyzer() {
|
||||||
|
let audioCtx = new AudioContext();
|
||||||
|
analyser = audioCtx.createAnalyser();
|
||||||
|
let source = audioCtx.createMediaElementSource(player);
|
||||||
|
|
||||||
|
source.connect(analyser);
|
||||||
|
source.connect(audioCtx.destination);
|
||||||
|
|
||||||
|
audio_data = new Uint8Array(analyser.frequencyBinCount);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user