parent
8e6703cb40
commit
9be22e4499
|
@ -219,6 +219,19 @@ final class ContentPlayerPlayManager: NSObject, ObservableObject {
|
||||||
player?.seek(to: cmTime)
|
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) {
|
private func generateUrl(contentId: Int, onSuccess: @escaping (String) -> Void, onFailure: @escaping () -> Void) {
|
||||||
if contentId < 0 {
|
if contentId < 0 {
|
||||||
onFailure()
|
onFailure()
|
||||||
|
|
|
@ -119,6 +119,13 @@ struct ContentPlayerView: View {
|
||||||
|
|
||||||
Spacer()
|
Spacer()
|
||||||
|
|
||||||
|
Image("ic_player_prev_10")
|
||||||
|
.onTapGesture {
|
||||||
|
playerManager.seekBackward(seconds: 10)
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
|
||||||
Image(playerManager.isPlaying ? "ic_player_pause" : "ic_player_play")
|
Image(playerManager.isPlaying ? "ic_player_pause" : "ic_player_play")
|
||||||
.onTapGesture {
|
.onTapGesture {
|
||||||
playerManager.playOrPause()
|
playerManager.playOrPause()
|
||||||
|
@ -126,6 +133,13 @@ struct ContentPlayerView: View {
|
||||||
|
|
||||||
Spacer()
|
Spacer()
|
||||||
|
|
||||||
|
Image("ic_player_next_10")
|
||||||
|
.onTapGesture {
|
||||||
|
playerManager.seekForward(seconds: 10)
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
|
||||||
Image("ic_skip_forward")
|
Image("ic_skip_forward")
|
||||||
.onTapGesture {
|
.onTapGesture {
|
||||||
playerManager.playNextContent()
|
playerManager.playNextContent()
|
||||||
|
|
Loading…
Reference in New Issue