From 3685a39a58dc1da5b0d258daca9f284d64802f6a Mon Sep 17 00:00:00 2001 From: Naoki Kishi Date: Thu, 6 Aug 2020 01:03:07 +0900 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=9C=9F=E3=83=81=E3=82=A7=E3=83=83?= =?UTF-8?q?=E3=82=AF=E3=81=A7Playing=E3=81=8C=E3=81=82=E3=81=A3=E3=81=A6?= =?UTF-8?q?=E3=81=84=E3=82=8B=E3=81=8B=E3=82=82=E3=83=81=E3=82=A7=E3=83=83?= =?UTF-8?q?=E3=82=AF=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- domain/entity/session.go | 11 +++++++++++ domain/entity/session_test.go | 17 +++++++++++++++++ usecase/session_timer.go | 3 +++ 3 files changed, 31 insertions(+) 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,