Live streams fix (fix #174, #175)

This commit is contained in:
Arkadiusz Fal
2022-07-22 00:44:21 +02:00
parent 827c64719c
commit e6baaa519a
8 changed files with 81 additions and 20 deletions

View File

@@ -54,6 +54,7 @@ struct ControlsOverlay: View {
Text(backend.label)
.padding(6)
.foregroundColor(player.activeBackend == backend ? .accentColor : .secondary)
.contentShape(Rectangle())
}
.buttonStyle(.plain)
}

View File

@@ -317,11 +317,12 @@ struct PlayerControls: View {
button("Seek Backward", systemImage: "gobackward.10", size: 25, cornerRadius: 5, background: false) {
player.backend.seek(relative: .secondsInDefaultTimescale(-10))
}
.disabled(player.liveStreamInAVPlayer)
#if os(tvOS)
.focused($focusedField, equals: .backward)
.focused($focusedField, equals: .backward)
#else
.keyboardShortcut("k", modifiers: [])
.keyboardShortcut(KeyEquivalent.leftArrow, modifiers: [])
.keyboardShortcut("k", modifiers: [])
.keyboardShortcut(KeyEquivalent.leftArrow, modifiers: [])
#endif
}
@@ -329,11 +330,12 @@ struct PlayerControls: View {
button("Seek Forward", systemImage: "goforward.10", size: 25, cornerRadius: 5, background: false) {
player.backend.seek(relative: .secondsInDefaultTimescale(10))
}
.disabled(player.liveStreamInAVPlayer)
#if os(tvOS)
.focused($focusedField, equals: .forward)
.focused($focusedField, equals: .forward)
#else
.keyboardShortcut("l", modifiers: [])
.keyboardShortcut(KeyEquivalent.rightArrow, modifiers: [])
.keyboardShortcut("l", modifiers: [])
.keyboardShortcut(KeyEquivalent.rightArrow, modifiers: [])
#endif
}

View File

@@ -108,6 +108,7 @@ struct TimelineView: View {
.animation(.easeOut, value: thumbTooltipOffset)
HStack(spacing: 4) {
Text((dragging ? projectedValue : nil)?.formattedAsPlaybackTime(allowZero: true) ?? playerTime.currentPlaybackTime)
.opacity(player.liveStreamInAVPlayer ? 0 : 1)
.frame(minWidth: 35)
#if os(tvOS)
.font(.system(size: 20))
@@ -190,7 +191,7 @@ struct TimelineView: View {
)
#endif
}
.opacity(player.liveStreamInAVPlayer ? 0 : 1)
.overlay(GeometryReader { proxy in
Color.clear
.onAppear {
@@ -209,12 +210,8 @@ struct TimelineView: View {
})
#endif
Text(dragging ? playerTime.durationPlaybackTime : playerTime.withoutSegmentsPlaybackTime)
.clipShape(RoundedRectangle(cornerRadius: 3))
.frame(minWidth: 35)
#if os(tvOS)
.font(.system(size: 20))
#endif
durationView
.frame(minWidth: 30, alignment: .trailing)
}
.clipShape(RoundedRectangle(cornerRadius: 3))
.font(.system(size: 9).monospacedDigit())
@@ -222,6 +219,37 @@ struct TimelineView: View {
}
}
@ViewBuilder var durationView: some View {
if player.live {
if player.playingLive || player.activeBackend == .appleAVPlayer {
Text("LIVE")
.fontWeight(.bold)
.padding(2)
.foregroundColor(.white)
.background(RoundedRectangle(cornerRadius: 2).foregroundColor(.red))
} else {
Button {
if let duration = player.videoDuration {
player.backend.seek(to: duration - 5)
}
} label: {
Text("LIVE")
.fontWeight(.bold)
.padding(2)
.foregroundColor(.primary)
.background(RoundedRectangle(cornerRadius: 2).strokeBorder(.red, lineWidth: 1).foregroundColor(.white))
}
}
} else {
Text(dragging ? playerTime.durationPlaybackTime : playerTime.withoutSegmentsPlaybackTime)
.clipShape(RoundedRectangle(cornerRadius: 3))
.frame(minWidth: 35)
#if os(tvOS)
.font(.system(size: 20))
#endif
}
}
var tooltipVeritcalOffset: Double {
var offset = -20.0