Fixed audio not starting on mobile
This commit is contained in:
@@ -184,7 +184,6 @@ class LMSMediaPlayer {
|
|||||||
let source = this.#audioCtx.createMediaElementSource(this.#elems.audio);
|
let source = this.#audioCtx.createMediaElementSource(this.#elems.audio);
|
||||||
source.connect(this.#gainNode);
|
source.connect(this.#gainNode);
|
||||||
this.#gainNode.connect(this.#audioCtx.destination);
|
this.#gainNode.connect(this.#audioCtx.destination);
|
||||||
this.#audioCtx.resume(); // not sure of this
|
|
||||||
|
|
||||||
if ("mediaSession" in navigator) {
|
if ("mediaSession" in navigator) {
|
||||||
navigator.mediaSession.setActionHandler("play", () => {
|
navigator.mediaSession.setActionHandler("play", () => {
|
||||||
@@ -268,6 +267,10 @@ class LMSMediaPlayer {
|
|||||||
#playPause() {
|
#playPause() {
|
||||||
this.#initAudioCtx();
|
this.#initAudioCtx();
|
||||||
|
|
||||||
|
if (this.#audioCtx.state === "suspended") {
|
||||||
|
this.#audioCtx.resume().catch(err => console.warn(err));
|
||||||
|
}
|
||||||
|
|
||||||
if (this.#elems.audio.paused && this.#elems.audio.children.length > 0) {
|
if (this.#elems.audio.paused && this.#elems.audio.children.length > 0) {
|
||||||
this.#playTrack();
|
this.#playTrack();
|
||||||
}
|
}
|
||||||
@@ -355,6 +358,8 @@ class LMSMediaPlayer {
|
|||||||
if (!mode)
|
if (!mode)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
let wasPlaying = !this.#elems.audio.paused;
|
||||||
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case LMSMediaPlayer.#Mode.Transcoding:
|
case LMSMediaPlayer.#Mode.Transcoding:
|
||||||
this.#offset = seekTime;
|
this.#offset = seekTime;
|
||||||
@@ -362,15 +367,16 @@ class LMSMediaPlayer {
|
|||||||
this.#addAudioSource(this.#audioTranscodingSrc + "&offset=" + this.#offset);
|
this.#addAudioSource(this.#audioTranscodingSrc + "&offset=" + this.#offset);
|
||||||
this.#elems.audio.load();
|
this.#elems.audio.load();
|
||||||
this.#elems.audio.currentTime = 0;
|
this.#elems.audio.currentTime = 0;
|
||||||
this.#playTrack();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LMSMediaPlayer.#Mode.File:
|
case LMSMediaPlayer.#Mode.File:
|
||||||
this.#elems.audio.currentTime = seekTime;
|
this.#elems.audio.currentTime = seekTime;
|
||||||
this.#playTrack();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (wasPlaying)
|
||||||
|
this.#playTrack();
|
||||||
|
|
||||||
this.#updateMediaSessionState();
|
this.#updateMediaSessionState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user