Skip to content

Commit

Permalink
fix(ajax player): reset tracks on player close
Browse files Browse the repository at this point in the history
  • Loading branch information
mrilyew committed Dec 7, 2024
1 parent e329d3d commit 21f3ebe
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
26 changes: 22 additions & 4 deletions Web/static/js/al_music.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,11 @@ window.player = new class {
this.dashPlayer.initialize(this.audioPlayer, c_track.url, false);
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)
}

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)
}

Expand All @@ -324,6 +324,10 @@ window.player = new class {
u(this.audioPlayer).trigger('volumechange')
}

hasContext() {
return this.context.object && this.context.object.url
}

switchTracks(id1, id2) {
const first_audio = this.__findTrack(id1)
const first_audio_index = this.__findTrack(id1, true)
Expand Down Expand Up @@ -449,6 +453,10 @@ window.player = new class {

// Добавляем ощущение продуманности.
__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')
}

Expand Down Expand Up @@ -488,11 +496,14 @@ window.player = new class {
if(this.audioPlayer.paused) {
return
}
if(!this.current_track_id || this.current_track_id == 0) {
return
}
this.ajCreate()
this.__updateFace()
}
} else {
this.ajClose(false)
this.ajClose(false, false)
this.is_closed = false
if(this.tracks.length < 1) {
if(window.__current_page_audio_context) {
Expand Down Expand Up @@ -682,11 +693,18 @@ window.player = new class {
}
}

ajClose(pause = true) {
ajClose(pause = true, clearTracks = true) {
this.is_closed = true
if(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')
}
Expand Down
4 changes: 4 additions & 0 deletions Web/static/js/al_wall.js
Original file line number Diff line number Diff line change
Expand Up @@ -2371,6 +2371,10 @@ const showMoreObserver = new IntersectionObserver(entries => {
if(u('.scroll_container').length < 1) {
return
}

/*if(window.player && window.player.isAtAudiosPage() && !window.player.isAtCurrentContextPage()) {
return
}*/

const target = u(x.target)
if(target.length < 1 || target.hasClass('paginator-at-top')) {
Expand Down

0 comments on commit 21f3ebe

Please sign in to comment.