Skip to content

Commit fc09f80

Browse files
committed
feat: add stop API call
1 parent 046cb36 commit fc09f80

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

api-spec.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ paths:
129129
responses:
130130
200:
131131
description: Successful response
132+
/player/stop:
133+
post:
134+
description: Stop playback and disconnect session
135+
responses:
136+
200:
137+
description: Successful response
132138
/player/playpause:
133139
post:
134140
description: Resume playback when paused, or pause playback when playing

daemon/api_server.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ const (
6666
ApiRequestTypePrev ApiRequestType = "prev"
6767
ApiRequestTypeNext ApiRequestType = "next"
6868
ApiRequestTypePlay ApiRequestType = "play"
69+
ApiRequestTypeStop ApiRequestType = "stop"
6970
ApiRequestTypeGetVolume ApiRequestType = "get_volume"
7071
ApiRequestTypeSetVolume ApiRequestType = "set_volume"
7172
ApiRequestTypeSetRepeatingContext ApiRequestType = "repeating_context"
@@ -494,6 +495,14 @@ func (s *ConcreteApiServer) serve() {
494495

495496
s.handleRequest(ApiRequest{Type: ApiRequestTypePause}, w)
496497
})
498+
m.HandleFunc("/player/stop", func(w http.ResponseWriter, r *http.Request) {
499+
if r.Method != "POST" {
500+
w.WriteHeader(http.StatusMethodNotAllowed)
501+
return
502+
}
503+
504+
s.handleRequest(ApiRequest{Type: ApiRequestTypeStop}, w)
505+
})
497506
m.HandleFunc("/player/playpause", func(w http.ResponseWriter, r *http.Request) {
498507
if r.Method != "POST" {
499508
w.WriteHeader(http.StatusMethodNotAllowed)

daemon/player.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,9 @@ func (p *AppPlayer) handleApiRequest(ctx context.Context, req ApiRequest) (any,
479479
case ApiRequestTypePause:
480480
_ = p.pause(ctx)
481481
return nil, nil
482+
case ApiRequestTypeStop:
483+
_ = p.stopPlayback(ctx)
484+
return nil, nil
482485
case ApiRequestTypePlayPause:
483486
if p.state.player.IsPaused {
484487
_ = p.play(ctx)

0 commit comments

Comments
 (0)