diff --git a/domain/entity/session.go b/domain/entity/session.go index 994c2050..7bfcd307 100644 --- a/domain/entity/session.go +++ b/domain/entity/session.go @@ -130,6 +130,17 @@ func (s *Session) IsPlayingCorrectTrack(playingInfo *CurrentPlayingInfo) error { }) return fmt.Errorf("session playing different track: queue track %s, but playing track %v: %w", s.QueueTracks[s.QueueHead].URI, playingInfo.Track, ErrSessionPlayingDifferentTrack) } + + if playingInfo.Playing != s.IsPlaying() { + logger.Infoj(map[string]interface{}{ + "message": "session playing, but spotify is not playing", + "queueTrack": s.QueueTracks[s.QueueHead].URI, + "playingTrack": playingInfo.Track, + }) + return fmt.Errorf("session playing, but spotify is not playing: %w", ErrSessionPlayingDifferentTrack) + + } + return nil } diff --git a/domain/entity/session_test.go b/domain/entity/session_test.go index 40922ecd..82dcda53 100644 --- a/domain/entity/session_test.go +++ b/domain/entity/session_test.go @@ -477,6 +477,23 @@ func TestSession_IsPlayingCorrectTrack(t *testing.T) { playingInfo: nil, wantErr: true, }, + { + name: "再生されているはずなのにSpotify側が一時停止していたらエラー", + session: &Session{ + StateType: Play, + QueueHead: 0, + QueueTracks: []*QueueTrack{ + {URI: "spotify:track:5uQ0vKy2973Y9IUCd1wMEF"}, + }, + }, + playingInfo: &CurrentPlayingInfo{ + Playing: false, + Progress: 0, + Track: &Track{}, + Device: &Device{}, + }, + wantErr: true, + }, { name: "再生が終了してStopになっていたらエラーにならない", session: &Session{ diff --git a/usecase/session_timer.go b/usecase/session_timer.go index 79647c47..47c01b6f 100644 --- a/usecase/session_timer.go +++ b/usecase/session_timer.go @@ -212,6 +212,9 @@ func (s *SessionTimerUseCase) handleTrackEndTx(sessionID string) func(ctx contex track := sess.TrackURIShouldBeAddedWhenHandleTrackEnd() if track != "" { + // TODO: Spotifyアプリを閉じた後、ずっとRelaymを開かないとINTERRUPTにならずにここまでたどり着いて + // active device not foundになってしまう + // そのときstateはPLAYのままなので表示がバグる if err := s.playerCli.Enqueue(ctx, track, sess.DeviceID); err != nil { return &handleTrackEndResponse{ nextTrack: false,