콘텐츠 플레이어
- 10초 이전/이후로 이동하는 기능 추가
This commit is contained in:
@@ -219,6 +219,19 @@ final class ContentPlayerPlayManager: NSObject, ObservableObject {
|
||||
player?.seek(to: cmTime)
|
||||
}
|
||||
|
||||
func seekBackward(seconds: Double) {
|
||||
guard let currentTime = player?.currentTime() else { return }
|
||||
let newTimeInSeconds = CMTimeGetSeconds(currentTime) - seconds
|
||||
seek(to: max(newTimeInSeconds, 0))
|
||||
}
|
||||
|
||||
func seekForward(seconds: Double) {
|
||||
guard let currentTime = player?.currentTime(), let duration = player?.currentItem?.duration else { return }
|
||||
let newTimeInSeconds = CMTimeGetSeconds(currentTime) + seconds
|
||||
let durationInSeconds = CMTimeGetSeconds(duration)
|
||||
seek(to: min(newTimeInSeconds, durationInSeconds))
|
||||
}
|
||||
|
||||
private func generateUrl(contentId: Int, onSuccess: @escaping (String) -> Void, onFailure: @escaping () -> Void) {
|
||||
if contentId < 0 {
|
||||
onFailure()
|
||||
|
@@ -119,6 +119,13 @@ struct ContentPlayerView: View {
|
||||
|
||||
Spacer()
|
||||
|
||||
Image("ic_player_prev_10")
|
||||
.onTapGesture {
|
||||
playerManager.seekBackward(seconds: 10)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
Image(playerManager.isPlaying ? "ic_player_pause" : "ic_player_play")
|
||||
.onTapGesture {
|
||||
playerManager.playOrPause()
|
||||
@@ -126,6 +133,13 @@ struct ContentPlayerView: View {
|
||||
|
||||
Spacer()
|
||||
|
||||
Image("ic_player_next_10")
|
||||
.onTapGesture {
|
||||
playerManager.seekForward(seconds: 10)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
Image("ic_skip_forward")
|
||||
.onTapGesture {
|
||||
playerManager.playNextContent()
|
||||
|
Reference in New Issue
Block a user