Skip to content

Commit 61feab1

Browse files
authored
Merge pull request #186 from camphor-/fix-is-playing-crrect-track
同期チェックでPlayingが正しいかもかもチェックする
2 parents 1758f33 + 3685a39 commit 61feab1

3 files changed

Lines changed: 31 additions & 0 deletions

File tree

domain/entity/session.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,17 @@ func (s *Session) IsPlayingCorrectTrack(playingInfo *CurrentPlayingInfo) error {
130130
})
131131
return fmt.Errorf("session playing different track: queue track %s, but playing track %v: %w", s.QueueTracks[s.QueueHead].URI, playingInfo.Track, ErrSessionPlayingDifferentTrack)
132132
}
133+
134+
if playingInfo.Playing != s.IsPlaying() {
135+
logger.Infoj(map[string]interface{}{
136+
"message": "session playing, but spotify is not playing",
137+
"queueTrack": s.QueueTracks[s.QueueHead].URI,
138+
"playingTrack": playingInfo.Track,
139+
})
140+
return fmt.Errorf("session playing, but spotify is not playing: %w", ErrSessionPlayingDifferentTrack)
141+
142+
}
143+
133144
return nil
134145
}
135146

domain/entity/session_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,23 @@ func TestSession_IsPlayingCorrectTrack(t *testing.T) {
477477
playingInfo: nil,
478478
wantErr: true,
479479
},
480+
{
481+
name: "再生されているはずなのにSpotify側が一時停止していたらエラー",
482+
session: &Session{
483+
StateType: Play,
484+
QueueHead: 0,
485+
QueueTracks: []*QueueTrack{
486+
{URI: "spotify:track:5uQ0vKy2973Y9IUCd1wMEF"},
487+
},
488+
},
489+
playingInfo: &CurrentPlayingInfo{
490+
Playing: false,
491+
Progress: 0,
492+
Track: &Track{},
493+
Device: &Device{},
494+
},
495+
wantErr: true,
496+
},
480497
{
481498
name: "再生が終了してStopになっていたらエラーにならない",
482499
session: &Session{

usecase/session_timer.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ func (s *SessionTimerUseCase) handleTrackEndTx(sessionID string) func(ctx contex
212212

213213
track := sess.TrackURIShouldBeAddedWhenHandleTrackEnd()
214214
if track != "" {
215+
// TODO: Spotifyアプリを閉じた後、ずっとRelaymを開かないとINTERRUPTにならずにここまでたどり着いて
216+
// active device not foundになってしまう
217+
// そのときstateはPLAYのままなので表示がバグる
215218
if err := s.playerCli.Enqueue(ctx, track, sess.DeviceID); err != nil {
216219
return &handleTrackEndResponse{
217220
nextTrack: false,

0 commit comments

Comments
 (0)