fix(ajax player): reset tracks on player close

This commit is contained in:
mrilyew 2024-12-07 21:42:30 +03:00
parent e329d3dcd4
commit 21f3ebea3d
2 changed files with 26 additions and 4 deletions

View file

@ -307,11 +307,11 @@ window.player = new class {
this.dashPlayer.initialize(this.audioPlayer, c_track.url, false); this.dashPlayer.initialize(this.audioPlayer, c_track.url, false);
this.dashPlayer.setProtectionData(protData) this.dashPlayer.setProtectionData(protData)
if(!this.nextTrack && Math.max(...this.context["playedPages"]) < this.context["pagesCount"]) { if(!this.nextTrack && this.hasContext() && Math.max(...this.context["playedPages"]) < this.context["pagesCount"]) {
await this.loadContext(Number(Math.max(...this.context["playedPages"])) + 1, true) await this.loadContext(Number(Math.max(...this.context["playedPages"])) + 1, true)
} }
if(!this.previousTrack && (Math.min(...this.context["playedPages"]) > 1)) { if(!this.previousTrack && this.hasContext() && (Math.min(...this.context["playedPages"]) > 1)) {
await this.loadContext(Math.min(...this.context["playedPages"]) - 1, false) await this.loadContext(Math.min(...this.context["playedPages"]) - 1, false)
} }
@ -324,6 +324,10 @@ window.player = new class {
u(this.audioPlayer).trigger('volumechange') u(this.audioPlayer).trigger('volumechange')
} }
hasContext() {
return this.context.object && this.context.object.url
}
switchTracks(id1, id2) { switchTracks(id1, id2) {
const first_audio = this.__findTrack(id1) const first_audio = this.__findTrack(id1)
const first_audio_index = this.__findTrack(id1, true) const first_audio_index = this.__findTrack(id1, true)
@ -449,6 +453,10 @@ window.player = new class {
// Добавляем ощущение продуманности. // Добавляем ощущение продуманности.
__highlightActiveTrack() { __highlightActiveTrack() {
if(!this.isAtCurrentContextPage()) {
return
}
u(`.audiosContainer .audioEmbed[data-realid='${this.current_track_id}'] .audioEntry, .audios_padding .audioEmbed[data-realid='${this.current_track_id}'] .audioEntry`).addClass('nowPlaying') u(`.audiosContainer .audioEmbed[data-realid='${this.current_track_id}'] .audioEntry, .audios_padding .audioEmbed[data-realid='${this.current_track_id}'] .audioEntry`).addClass('nowPlaying')
} }
@ -488,11 +496,14 @@ window.player = new class {
if(this.audioPlayer.paused) { if(this.audioPlayer.paused) {
return return
} }
if(!this.current_track_id || this.current_track_id == 0) {
return
}
this.ajCreate() this.ajCreate()
this.__updateFace() this.__updateFace()
} }
} else { } else {
this.ajClose(false) this.ajClose(false, false)
this.is_closed = false this.is_closed = false
if(this.tracks.length < 1) { if(this.tracks.length < 1) {
if(window.__current_page_audio_context) { if(window.__current_page_audio_context) {
@ -682,11 +693,18 @@ window.player = new class {
} }
} }
ajClose(pause = true) { ajClose(pause = true, clearTracks = true) {
this.is_closed = true this.is_closed = true
if(pause) { if(pause) {
this.pause() this.pause()
} }
if(clearTracks) {
this.__resetContext()
this.__updateFace()
this.current_track_id = null
this.audioPlayer.currentTime = 0
this.undump()
}
u('#ajax_audio_player').addClass('hidden') u('#ajax_audio_player').addClass('hidden')
} }

View file

@ -2371,6 +2371,10 @@ const showMoreObserver = new IntersectionObserver(entries => {
if(u('.scroll_container').length < 1) { if(u('.scroll_container').length < 1) {
return return
} }
/*if(window.player && window.player.isAtAudiosPage() && !window.player.isAtCurrentContextPage()) {
return
}*/
const target = u(x.target) const target = u(x.target)
if(target.length < 1 || target.hasClass('paginator-at-top')) { if(target.length < 1 || target.hasClass('paginator-at-top')) {