Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ public final class DreamAudioPlayerView: UIView {

private let disposeBag = DisposeBag()

private var audioPlayer: AVAudioPlayer!
public var audioPlayer: AVAudioPlayer!
private var audioTimer: Timer!
private var audioFile: URL?
private let timePlayerSelector: Selector = #selector(updatePlayTime)

private var playStatus = playStatus.notStart

public let isPauseAudio = PublishRelay<Bool>()

private lazy var playAndPauseButton: UIButton = {
let button = UIButton()
button.setImage(RDDSKitAsset.Images.icnStart.image, for: .normal)
Expand Down Expand Up @@ -80,6 +82,7 @@ public final class DreamAudioPlayerView: UIView {
self.setUI()
self.setLayout()
self.bind()
self.setAudioSession()
self.initPlay()
}

Expand Down Expand Up @@ -128,8 +131,8 @@ extension DreamAudioPlayerView {
audioPlayer = try AVAudioPlayer(contentsOf: audioFile)

audioPlayer.delegate = self
audioPlayer.prepareToPlay()
audioPlayer.volume = 1.0
audioPlayer.prepareToPlay()
audioPlayTimeLabel.text = convertNSTimeInterval2String(audioPlayer.duration)

} catch let error as NSError {
Expand Down Expand Up @@ -180,10 +183,28 @@ extension DreamAudioPlayerView {
}
})
.disposed(by: self.disposeBag)

isPauseAudio
.withUnretained(self)
.subscribe(onNext: { (owner, isPauseAudio) in
if isPauseAudio {
owner.setPlayStatus(false)
owner.audioPlayer.pause()
}
Comment on lines +190 to +193
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍👍

Comment on lines +187 to +193
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

현재 사용되는 곳을 보니 Bool타입 중에서 true만 사용하고 있고, public method를 통해서 처리할 수 있을 것 같은데, 메모리 효율을 위해 method를 사용하는 방식으로 사용하는 것은 어떨까요?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@L-j-h-c 넵 ! 리팩과정에서 한번 수정해보겠습니다 :)

}).disposed(by: self.disposeBag)
}
}

extension DreamAudioPlayerView: AVAudioPlayerDelegate {
private func setAudioSession() {
let audioSession = AVAudioSession.sharedInstance()
do {
try audioSession.setCategory(AVAudioSession.Category.playback, mode: .default)
} catch {
print("audioSession error: \(error.localizedDescription)")
}
}
Comment on lines +199 to +206
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍 👍


public func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) {
audioTimer.invalidate()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ public final class DreamRecordViewController: UIViewController {
self.setLayout()
}

public override func viewWillDisappear(_ animated: Bool) {
self.stopAudio()
}

// MARK: - UI & Layout
private func setUI() {
self.view.backgroundColor = .none
Expand Down Expand Up @@ -176,4 +180,8 @@ public final class DreamRecordViewController: UIViewController {
}
}
}

private func stopAudio() {
self.dreamAudioPlayerView.isPauseAudio.accept(true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ extension DreamDetailMoreVC {
self.shareButton.rx.tap
.asDriver()
.drive(onNext: {
AnalyticsManager.log(event: .clickDetailMoreShare)
self.shareToInstagramStories()
}).disposed(by: self.disposeBag)
}
Expand Down Expand Up @@ -259,6 +260,7 @@ extension DreamDetailMoreVC {
UIPasteboard.general.setItems([pasteboardItems], options: pasteboardOptions)
UIApplication.shared.open(storyShareURL, options: [:], completionHandler: nil)
shareView.isHidden = true
AnalyticsManager.log(event: .clickDetailMoreShareUpload)
} else {
let alert = UIAlertController(title: "알림", message: "인스타그램이 필요합니다", preferredStyle: .alert)
let ok = UIAlertAction(title: "확인", style: .default, handler: nil)
Expand Down