Skip to content

Commit

Permalink
Merge pull request #101 from lenamin/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
lenamin authored Aug 29, 2023
2 parents cd81646 + b3d23fe commit a893602
Show file tree
Hide file tree
Showing 133 changed files with 264 additions and 160 deletions.
312 changes: 208 additions & 104 deletions Tars/Tars.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
42 changes: 42 additions & 0 deletions Tars/Tars/Network/Manager/SoundManager/SoundManager.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// SoundManager.swift
// Tars
//
// Created by Lena on 2022/11/26.
//

import Foundation
import AVFoundation

class AudioManager {
static let shared = AudioManager()
var audioPlayer: AVAudioPlayer?

init() {}

public func playAudio(pre: String = "Searching_",
fileName: String = "Jupiter",
audioExtension: String = "mp3",
audioVolume: Float = 0.7,
isLoop: Bool = true) {
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)
}
}

public func pauseAudio() {
audioPlayer?.pause()
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,18 @@ class InfoViewController: UIViewController {
configureConstraints()
navigationItem.title = planet.planetKoreanName
// 해당 천체의 사운드 재생
audioManager.playAudio(fileName: planet.planetEnglishName)
audioManager.playAudio(pre: "Detail_",
fileName: planet.planetEnglishName,
audioExtension: "mp3",
audioVolume: 0.4,
isLoop: true)
}

/// 화면이 사라질 경우 사운드 재생 중지
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(true)
audioManager.pauseAudio()
audioManager.audioPlayer?.prepareToPlay()
}

private func configureConstraints() {
Expand Down
Loading

0 comments on commit a893602

Please sign in to comment.