Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] 폴더링 및 앱용량 최적화 #101

Merged
merged 13 commits into from
Aug 29, 2023

Conversation

lenamin
Copy link
Member

@lenamin lenamin commented Aug 28, 2023

작업내용

  • 가독성을 위해 전체적인 폴더링 구조를 변경하였습니다.
  • DetailView에서 쓰이던 aif 오디오파일들을 mp3 로 교체해 앱 용량을 줄였습니다.
  • 반복적으로 사용되는 여러 개의 메서드들을 하나로 합쳤습니다
    • 기존 코드
 public func playAudio(fileName: String) {
        guard let url = Bundle.main.url(forResource: "Detail_\(fileName)", withExtension: "aif") else { return }
        
        do {
            try audioPlayer = AVAudioPlayer(contentsOf: url)
            
            audioPlayer?.prepareToPlay()
            audioPlayer?.volume = 0.5
            audioPlayer?.play()
            audioPlayer?.numberOfLoops = -1
        } catch {
            print(error.localizedDescription)
        }
    }
    
    public func playDetectingAudio(fileName: String) {
        guard let url = Bundle.main.url(forResource: "\(fileName)", withExtension: "wav") else { return }
        
        do {
            try audioPlayer = AVAudioPlayer(contentsOf: url)
            
            audioPlayer?.prepareToPlay()
            audioPlayer?.volume = 0.3
            audioPlayer?.play()
            
        } catch {
            print(error.localizedDescription)
        }
    }
  • 변경된 코드
public func playAudio(pre: String,
                          fileName: String,
                          audioExtension: String,
                          audioVolume: Float,
                          isLoop: Bool) {
        guard let url = Bundle.main.url(forResource: "\(pre)\(fileName)", withExtension: "\(audioExtension)") else { return }
        
        do {
            try audioPlayer = AVAudioPlayer(contentsOf: url)
            
            audioPlayer?.prepareToPlay()
            audioPlayer?.volume = audioVolume
            audioPlayer?.play()
            if isLoop {
                audioPlayer?.numberOfLoops = -1
            }
            
        } catch {
            print(error.localizedDescription)
        }
    }

playAudio() 메서드의 각 파라미터에 원하는 접두어 (Detail_ vs Searching_), 행성 이름 (filename), 확장자 (wav vs mp3), 볼륨 크기 (0.0 ~ 1.0), 반복 여부 (true or false) 를 넣어주면 매번 다른 메서드를 호출하거나 기억하지 않아도 playAudio()기능을 사용할 수 있습니다.

  • Detail View 로 들어가면 음량이 갑자기 커지는 문제를 수정하였습니다
    0.7 > 0.4 로 조정

리뷰포인트

  • 리팩토링을 진행하며 혹시나 놓친 예외사항이 있지는 않은지

Checklist

  • 빌드를 위해 SceneDelegate 수정한 것 PR로 올리지 않았는지 확인
  • 필요없는 주석, 프린트문 제거했는지 확인
  • 컨벤션 지켰는지 확인

@lenamin lenamin added the 🛠fix warning 같은 문제 수정 label Aug 28, 2023
@lenamin lenamin self-assigned this Aug 28, 2023
Copy link
Collaborator

@HeejiSohn HeejiSohn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

항상 SpaceOver 아껴줘서 감사합니당🙏🙏

Comment on lines 44 to 54
public func playAudio(fileName: String) {
guard let url = Bundle.main.url(forResource: "Detail_\(fileName)", withExtension: "aif") else { return }

do {
try audioPlayer = AVAudioPlayer(contentsOf: url)

audioPlayer?.prepareToPlay()
audioPlayer?.volume = 0.7
audioPlayer?.volume = 0.5
audioPlayer?.play()
audioPlayer?.numberOfLoops = -1
} catch {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

playAudio 메소드는 하나로 합치려는거 아니었나요?🤔🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아 이 메서드는 AudioPlayer 자체 메서드입니다! 제가 합친 것은 detail, search 화면에서 별도로 사용했던 메서드를 합친거랍니당 :)

Copy link
Collaborator

@SohyeonKim-dev SohyeonKim-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥳 이 수많은 파일 계층들을 정리해주다니 , , 넘나 최고에유! 오랜만에 타스 코드 보니까 반갑기도 하구, 짱 좋아요 🥹💕 수고하셨습니다, 레나 :)

Comment on lines 17 to 20
/// pre: searching_ vs detail_
/// fileName: name of body
/// audioExtension: mp3 vs aif vs wav
/// audioVolume: 0.0 ~ 1.0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 주석들은 아래 playAudio 함수의 parameter에 대한 설명 파트인 것 같아요! 함수 호출 시 꼭 필요한 설명 같지만, 단순히 주석으로 달아두기 보다, 좀 더 나은 방식으로 정리해두면 좋을 것 같은데 ,, 마땅한 아이디어가 떠오르지 않습니다.. 🥲 hoxy 다른 방법이 있을까요?

  • enum으로 정의해두는 것도 하나의 방법이 될 것 같네요! (아니면 default 값을 지정해두는 것도,,!)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분은 정말 생각못했던 점이네요. 좋은 의견 감사합니다!
선택지를 제공하고싶어서 enum으로 해보려했으나 행성 종류가 많아 pre, fileName, audioExtension 모두를 enum 으로 만들기엔 불필요하게 비대해진다고 판단하여 default 값을 설정해두었습니다.

b3d23fe (#101)

Comment on lines -110 to +114
audioManager.playAudio(fileName: planet.planetEnglishName)
audioManager.playAudio(pre: "Detail_",
fileName: planet.planetEnglishName,
audioExtension: "mp3",
audioVolume: 0.4,
isLoop: true)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

새로운 함수를 호출할 때에는 이렇게 적용되는군요! :) audio 관련된 디테일들을 직접 제어할 수 있어서 훨씬 더 좋은 방법인 것 같습니다.

@lenamin lenamin merged commit a893602 into DeveloperAcademy-POSTECH:develop Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🛠fix warning 같은 문제 수정
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants