Can control playlist
This commit is contained in:
parent
1d091be264
commit
f7760416b9
7 changed files with 257 additions and 10 deletions
|
|
@ -14,6 +14,7 @@ type InputState struct {
|
|||
Name string `json:"name"`
|
||||
Active bool `json:"active"`
|
||||
Controlable bool `json:"controlable"`
|
||||
HasPlaylist bool `json:"hasplaylist"`
|
||||
Streams map[string]string `json:"streams,omitempty"`
|
||||
Mixable bool `json:"mixable"`
|
||||
Mixer map[string]*inputs.InputMixer `json:"mixer,omitempty"`
|
||||
|
|
@ -32,10 +33,16 @@ func declareInputsRoutes(cfg *config.Config, router *gin.RouterGroup) {
|
|||
mixer, _ = im.GetMixers()
|
||||
}
|
||||
|
||||
var hasPlaylist bool
|
||||
if p, withPlaylist := inp.(inputs.PlaylistInput); withPlaylist {
|
||||
hasPlaylist = p.HasPlaylist()
|
||||
}
|
||||
|
||||
ret[k] = &InputState{
|
||||
Name: inp.GetName(),
|
||||
Active: inp.IsActive(),
|
||||
Controlable: controlable,
|
||||
HasPlaylist: hasPlaylist,
|
||||
Streams: inp.CurrentlyPlaying(),
|
||||
Mixable: mixable,
|
||||
Mixer: mixer,
|
||||
|
|
@ -57,11 +64,16 @@ func declareInputsRoutes(cfg *config.Config, router *gin.RouterGroup) {
|
|||
if mixable {
|
||||
mixer, _ = im.GetMixers()
|
||||
}
|
||||
var hasPlaylist bool
|
||||
if p, withPlaylist := inp.(inputs.PlaylistInput); withPlaylist {
|
||||
hasPlaylist = p.HasPlaylist()
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, &InputState{
|
||||
Name: inp.GetName(),
|
||||
Active: inp.IsActive(),
|
||||
Controlable: controlable,
|
||||
HasPlaylist: hasPlaylist,
|
||||
Streams: inp.CurrentlyPlaying(),
|
||||
Mixable: mixable,
|
||||
Mixer: mixer,
|
||||
|
|
@ -84,6 +96,7 @@ func declareInputsRoutes(cfg *config.Config, router *gin.RouterGroup) {
|
|||
streamRoutes := inputsRoutes.Group("/streams/:stream")
|
||||
streamRoutes.Use(StreamHandler)
|
||||
|
||||
// ControlableInput
|
||||
streamRoutes.POST("/pause", func(c *gin.Context) {
|
||||
input, ok := c.MustGet("input").(inputs.ControlableInput)
|
||||
if !ok {
|
||||
|
|
@ -99,6 +112,8 @@ func declareInputsRoutes(cfg *config.Config, router *gin.RouterGroup) {
|
|||
|
||||
c.JSON(http.StatusOK, true)
|
||||
})
|
||||
|
||||
// MixableInput
|
||||
streamRoutes.POST("/volume", func(c *gin.Context) {
|
||||
input, ok := c.MustGet("input").(inputs.MixableInput)
|
||||
if !ok {
|
||||
|
|
@ -121,6 +136,47 @@ func declareInputsRoutes(cfg *config.Config, router *gin.RouterGroup) {
|
|||
|
||||
c.JSON(http.StatusOK, true)
|
||||
})
|
||||
|
||||
// PlaylistInput
|
||||
streamRoutes.POST("/has_playlist", func(c *gin.Context) {
|
||||
input, ok := c.MustGet("input").(inputs.PlaylistInput)
|
||||
if !ok {
|
||||
c.AbortWithStatusJSON(http.StatusMethodNotAllowed, gin.H{"errmsg": "The source doesn't support that"})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, input.HasPlaylist())
|
||||
})
|
||||
streamRoutes.POST("/next_track", func(c *gin.Context) {
|
||||
input, ok := c.MustGet("input").(inputs.PlaylistInput)
|
||||
if !ok {
|
||||
c.AbortWithStatusJSON(http.StatusMethodNotAllowed, gin.H{"errmsg": "The source doesn't support that"})
|
||||
return
|
||||
}
|
||||
|
||||
err := input.NextTrack()
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusMethodNotAllowed, gin.H{"errmsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, true)
|
||||
})
|
||||
streamRoutes.POST("/prev_track", func(c *gin.Context) {
|
||||
input, ok := c.MustGet("input").(inputs.PlaylistInput)
|
||||
if !ok {
|
||||
c.AbortWithStatusJSON(http.StatusMethodNotAllowed, gin.H{"errmsg": "The source doesn't support that"})
|
||||
return
|
||||
}
|
||||
|
||||
err := input.PreviousTrack()
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusMethodNotAllowed, gin.H{"errmsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, true)
|
||||
})
|
||||
}
|
||||
|
||||
func InputHandler(c *gin.Context) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue