feat: Add Song radio option in tracklist.
At this moment this feature is only available on the Subsonic media provider. Using a Jellyfin server the "Play song radio" option will be disabled.
This commit is contained in:
@@ -145,6 +145,20 @@ func (m *Controller) connectTracklistActionsWithReplayGainMode(tracklist *widget
|
||||
tracklist.OnShare = func(trackID string) {
|
||||
go m.ShowShareDialog(trackID)
|
||||
}
|
||||
tracklist.OnPlaySongRadio = func (track *mediaprovider.Track) {
|
||||
go func() {
|
||||
tracks, err := m.GetSongRadioTracks(track)
|
||||
if err != nil {
|
||||
log.Printf("Error getting song radio: ", err)
|
||||
return
|
||||
}
|
||||
m.App.PlaybackManager.LoadTracks(tracks, false, false)
|
||||
if m.App.Config.ReplayGain.Mode == backend.ReplayGainAuto {
|
||||
m.App.PlaybackManager.SetReplayGainMode(mode)
|
||||
}
|
||||
m.App.PlaybackManager.PlayFromBeginning()
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Controller) ConnectAlbumGridActions(grid *widgets.GridView) {
|
||||
@@ -868,3 +882,23 @@ func (c *Controller) ShowAlbumInfoDialog(albumID, albumName string, albumCover i
|
||||
pop.Show()
|
||||
}()
|
||||
}
|
||||
|
||||
func (c *Controller) GetSongRadioTracks(sourceTrack *mediaprovider.Track) ([]*mediaprovider.Track, error) {
|
||||
r, ok := c.App.ServerManager.Server.(mediaprovider.SupportsSongRadio)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("Server does not support song radio")
|
||||
}
|
||||
|
||||
radioTracks, err := r.GetSongRadio(sourceTrack.ID, 100)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error getting song radio: ", err)
|
||||
}
|
||||
|
||||
// The goal of this implementation is to place the source track first in the queue.
|
||||
filteredTracks := sharedutil.FilterSlice(radioTracks, func(track *mediaprovider.Track) bool{
|
||||
return track.ID != sourceTrack.ID
|
||||
})
|
||||
tracks := []*mediaprovider.Track{sourceTrack}
|
||||
tracks = append(tracks, filteredTracks...)
|
||||
return tracks, nil
|
||||
}
|
||||
Reference in New Issue
Block a user