refactor(quick-14): make playOrLoadCurrentTrack and playCurrentTrack return bool
- playCurrentTrack returns false on load failure or play error - playOrLoadCurrentTrack propagates bool from load/play helpers - loadCurrentTrack already returned bool — no change needed
This commit is contained in:
+12
-6
@@ -1115,12 +1115,13 @@ func (q *Queue) EmitCurrentState() {
|
|||||||
// playOrLoadCurrentTrack loads the current track and optionally starts
|
// playOrLoadCurrentTrack loads the current track and optionally starts
|
||||||
// playback. When autoPlay is true it behaves like playCurrentTrack;
|
// playback. When autoPlay is true it behaves like playCurrentTrack;
|
||||||
// when false it only loads the file (leaving the player paused).
|
// when false it only loads the file (leaving the player paused).
|
||||||
func (q *Queue) playOrLoadCurrentTrack(autoPlay bool) {
|
// Returns true if the file was loaded (and optionally played) successfully.
|
||||||
|
func (q *Queue) playOrLoadCurrentTrack(autoPlay bool) bool {
|
||||||
if autoPlay {
|
if autoPlay {
|
||||||
q.playCurrentTrack()
|
return q.playCurrentTrack()
|
||||||
} else {
|
|
||||||
q.loadCurrentTrack()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return q.loadCurrentTrack()
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadCurrentTrack tells the player to load the current track without
|
// loadCurrentTrack tells the player to load the current track without
|
||||||
@@ -1166,9 +1167,10 @@ func (q *Queue) loadCurrentTrack() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// playCurrentTrack tells the player to load and play the current track.
|
// playCurrentTrack tells the player to load and play the current track.
|
||||||
func (q *Queue) playCurrentTrack() {
|
// Returns true if the file was loaded and playback started successfully.
|
||||||
|
func (q *Queue) playCurrentTrack() bool {
|
||||||
if !q.loadCurrentTrack() {
|
if !q.loadCurrentTrack() {
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
err := q.player.Play()
|
err := q.player.Play()
|
||||||
@@ -1178,7 +1180,11 @@ func (q *Queue) playCurrentTrack() {
|
|||||||
"Failed to play file from queue",
|
"Failed to play file from queue",
|
||||||
"filePath", track.FilePath, "err", err,
|
"filePath", track.FilePath, "err", err,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleCurrentTrackRemoved handles the case where the currently loaded
|
// handleCurrentTrackRemoved handles the case where the currently loaded
|
||||||
|
|||||||
Reference in New Issue
Block a user