From 6718f59a81f3d87af786a96e9a34b19e4cb8b3cb Mon Sep 17 00:00:00 2001 From: Gordon Choi Date: Fri, 2 Dec 2022 04:04:47 +0900 Subject: [PATCH] =?UTF-8?q?#142=20feat:=20=ED=99=94=EB=A9=B4=EC=9D=84=20?= =?UTF-8?q?=EB=B2=97=EC=96=B4=EB=82=98=EB=A9=B4=20=EC=9E=AC=EC=83=9D?= =?UTF-8?q?=EC=9D=B4=20=EB=A9=88=EC=B6=94=EB=8F=84=EB=A1=9D=20=EC=A1=B0?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Segno/Segno/Data/Session/MusicSession.swift | 30 ++++++++++++------- .../DiaryDetailViewController.swift | 10 +++---- .../ViewController/LoginViewController.swift | 2 +- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/Segno/Segno/Data/Session/MusicSession.swift b/Segno/Segno/Data/Session/MusicSession.swift index add48c7..1ae30da 100644 --- a/Segno/Segno/Data/Session/MusicSession.swift +++ b/Segno/Segno/Data/Session/MusicSession.swift @@ -43,19 +43,10 @@ final class MusicSession { } // 음악을 재생하는 함수 - func playMusic() { + func togglePlayer() { guard let song else { return } if !isPlaying { - player.queue = [song] - - Task { - do { - try await player.play() - } catch let error { - // TODO: 에러 처리 - print(error.localizedDescription) - } - } + playMusic(song: song) } else { player.pause() } @@ -63,4 +54,21 @@ final class MusicSession { // 뷰 컨트롤러를 나갈 때 큐를 비워 준다. // 뮤직세션, 샤잠세션은 싱글턴 인스턴스로 만들어 주는 것이 좋겠다. } + + private func playMusic(song: Song) { + player.queue = [song] + + Task { + do { + try await player.play() + } catch let error { + // TODO: 에러 처리 + print(error.localizedDescription) + } + } + } + + func stopMusic() { + player.stop() + } } diff --git a/Segno/Segno/Presentation/ViewController/DiaryDetailViewController.swift b/Segno/Segno/Presentation/ViewController/DiaryDetailViewController.swift index 96ea841..f5227f4 100644 --- a/Segno/Segno/Presentation/ViewController/DiaryDetailViewController.swift +++ b/Segno/Segno/Presentation/ViewController/DiaryDetailViewController.swift @@ -123,12 +123,12 @@ final class DiaryDetailViewController: UIViewController { musicSession.fetchMusic(term: MusicInfo.yokohama) } - override func touchesBegan(_ touches: Set, with event: UIEvent?) { - self.view.endEditing(true) + override func viewWillDisappear(_ animated: Bool) { + musicSession.stopMusic() } - private func bindPlayButton() { - musicContentView + override func touchesBegan(_ touches: Set, with event: UIEvent?) { + self.view.endEditing(true) } private func setupLayout() { @@ -242,7 +242,7 @@ final class DiaryDetailViewController: UIViewController { extension DiaryDetailViewController: MusicContentViewDelegate { func playButtonTapped() { - musicSession.playMusic() + musicSession.togglePlayer() } } diff --git a/Segno/Segno/Presentation/ViewController/LoginViewController.swift b/Segno/Segno/Presentation/ViewController/LoginViewController.swift index c6d55e2..bfe65f4 100644 --- a/Segno/Segno/Presentation/ViewController/LoginViewController.swift +++ b/Segno/Segno/Presentation/ViewController/LoginViewController.swift @@ -190,7 +190,7 @@ final class LoginViewController: UIViewController { } buttonStack.snp.makeConstraints { make in - make.centerY.equalToSuperview() + make.top.equalTo(subTitleLabel.snp.bottom) } buttonStack.arrangedSubviews.forEach {