ADD: Save volume settings in localstorage

This commit is contained in:
Edgardo Ramírez 2020-10-06 14:53:08 -05:00
parent 8aa5c33999
commit 84b81e440d

View file

@ -47,6 +47,7 @@ class OwncastPlayer {
this.startPlayer = this.startPlayer.bind(this); this.startPlayer = this.startPlayer.bind(this);
this.handleReady = this.handleReady.bind(this); this.handleReady = this.handleReady.bind(this);
this.handlePlaying = this.handlePlaying.bind(this); this.handlePlaying = this.handlePlaying.bind(this);
this.handleVolume = this.handleVolume.bind(this);
this.handleEnded = this.handleEnded.bind(this); this.handleEnded = this.handleEnded.bind(this);
this.handleError = this.handleError.bind(this); this.handleError = this.handleError.bind(this);
} }
@ -76,6 +77,7 @@ class OwncastPlayer {
startPlayer() { startPlayer() {
this.log('Start playing'); this.log('Start playing');
const source = { ...VIDEO_SRC } const source = { ...VIDEO_SRC }
this.vjsPlayer.volume(localStorage.getItem('owncastVolume'));
this.vjsPlayer.src(source); this.vjsPlayer.src(source);
// this.vjsPlayer.play(); // this.vjsPlayer.play();
}; };
@ -84,6 +86,7 @@ class OwncastPlayer {
this.log('on Ready'); this.log('on Ready');
this.vjsPlayer.on('error', this.handleError); this.vjsPlayer.on('error', this.handleError);
this.vjsPlayer.on('playing', this.handlePlaying); this.vjsPlayer.on('playing', this.handlePlaying);
this.vjsPlayer.on('volumechange', this.handleVolume);
this.vjsPlayer.on('ended', this.handleEnded); this.vjsPlayer.on('ended', this.handleEnded);
if (this.appPlayerReadyCallback) { if (this.appPlayerReadyCallback) {
@ -92,6 +95,10 @@ class OwncastPlayer {
} }
} }
handleVolume(e) {
localStorage.setItem('owncastVolume', this.vjsPlayer.volume());
}
handlePlaying() { handlePlaying() {
this.log('on Playing'); this.log('on Playing');
if (this.appPlayerPlayingCallback) { if (this.appPlayerPlayingCallback) {