Add music player
This commit is contained in:
parent
325175525b
commit
ad92c1866c
12 changed files with 989 additions and 38 deletions
src/music/player
|
@ -1,28 +1,13 @@
|
|||
class AudioManager {
|
||||
constructor(src) {
|
||||
this._context = new AudioContext();
|
||||
this.audio = new Audio(src);
|
||||
|
||||
let audio = this.audio;
|
||||
let context = this._context;
|
||||
|
||||
// Create audio graph
|
||||
let volume = context.createGain();
|
||||
let source = context.createMediaElementSource(audio);
|
||||
|
||||
source.connect(volume);
|
||||
volume.connect(context.destination);
|
||||
}
|
||||
}
|
||||
import AudioManager from "./audio_manager";
|
||||
import Controls from "./controls";
|
||||
import Display from "./display";
|
||||
|
||||
class Player {
|
||||
constructor(src="https://tlater.net/assets/Mseq_-_Journey.mp3") {
|
||||
this._ui = $("#playerUI");
|
||||
this._audioManager = new AudioManager(src);
|
||||
|
||||
let audioManager = this._audioManager;
|
||||
|
||||
audioManager.oncanplay = () => audioManager.audio.play();
|
||||
this._controls = new Controls(this._audioManager);
|
||||
this._display = new Display(this._audioManager);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue