mirror of
https://github.com/yattee/yattee.git
synced 2025-12-13 11:38:15 +00:00
Compare commits
1 Commits
changes-to
...
video-deta
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b4bcd0c0a0 |
@@ -4,7 +4,7 @@
|
||||
<dict>
|
||||
<key>com.apple.security.application-groups</key>
|
||||
<array>
|
||||
<string>group.ZYMM2HKXY2.yattee.app.url</string>
|
||||
<string>group.78Z5H3M6RJ.stream.yattee.app.urlbookmarks</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
@@ -11,7 +11,6 @@ final class MPVOGLView: GLKView {
|
||||
var mpvGL: UnsafeMutableRawPointer?
|
||||
var queue = DispatchQueue(label: "stream.yattee.opengl", qos: .userInteractive)
|
||||
var needsDrawing = true
|
||||
private var dirtyRegion: CGRect?
|
||||
|
||||
override init(frame: CGRect) {
|
||||
guard let context = EAGLContext(api: .openGLES2) else {
|
||||
@@ -86,7 +85,6 @@ final class MPVOGLView: GLKView {
|
||||
@objc private func updateFrame() {
|
||||
// Trigger the drawing process if needed
|
||||
if needsDrawing {
|
||||
markRegionAsDirty(bounds)
|
||||
setNeedsDisplay()
|
||||
}
|
||||
}
|
||||
@@ -102,60 +100,16 @@ final class MPVOGLView: GLKView {
|
||||
glClear(UInt32(GL_COLOR_BUFFER_BIT))
|
||||
}
|
||||
|
||||
// Function to set a dirty region when a part of the screen changes
|
||||
func markRegionAsDirty(_ region: CGRect) {
|
||||
if dirtyRegion == nil {
|
||||
dirtyRegion = region
|
||||
} else {
|
||||
// Expand the dirty region to include the new region
|
||||
dirtyRegion = dirtyRegion!.union(region)
|
||||
}
|
||||
}
|
||||
|
||||
// Logic to decide if only part of the screen needs updating
|
||||
private func needsPartialUpdate() -> Bool {
|
||||
// Check if there is a defined dirty region that needs updating
|
||||
if let dirtyRegion, !dirtyRegion.isEmpty {
|
||||
// Set up glScissor based on dirtyRegion coordinates
|
||||
glScissor(GLint(dirtyRegion.origin.x), GLint(dirtyRegion.origin.y), GLsizei(dirtyRegion.width), GLsizei(dirtyRegion.height))
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Call this function when you know the entire screen needs updating
|
||||
private func clearDirtyRegion() {
|
||||
dirtyRegion = nil
|
||||
}
|
||||
|
||||
override func draw(_: CGRect) {
|
||||
guard needsDrawing, let mpvGL else { return }
|
||||
|
||||
// Ensure the correct context is set
|
||||
guard EAGLContext.setCurrent(context) else {
|
||||
logger.error("Failed to set current OpenGL context.")
|
||||
return
|
||||
}
|
||||
|
||||
// Bind the default framebuffer
|
||||
glGetIntegerv(UInt32(GL_FRAMEBUFFER_BINDING), &defaultFBO!)
|
||||
|
||||
// Ensure the framebuffer is valid
|
||||
guard defaultFBO != nil && defaultFBO! != 0 else {
|
||||
logger.error("Invalid framebuffer ID.")
|
||||
return
|
||||
}
|
||||
|
||||
// Get the current viewport dimensions
|
||||
var dims: [GLint] = [0, 0, 0, 0]
|
||||
glGetIntegerv(GLenum(GL_VIEWPORT), &dims)
|
||||
|
||||
// Check if we need partial updates
|
||||
if needsPartialUpdate() {
|
||||
logger.info("Performing partial update with scissor test.")
|
||||
glEnable(GLenum(GL_SCISSOR_TEST))
|
||||
}
|
||||
|
||||
// Set up the OpenGL FBO data
|
||||
var data = mpv_opengl_fbo(
|
||||
fbo: Int32(defaultFBO!),
|
||||
@@ -175,23 +129,9 @@ final class MPVOGLView: GLKView {
|
||||
mpv_render_param(type: MPV_RENDER_PARAM_FLIP_Y, data: flipPtr),
|
||||
mpv_render_param()
|
||||
]
|
||||
// Call the render function and check for errors
|
||||
let result = mpv_render_context_render(OpaquePointer(mpvGL), ¶ms)
|
||||
if result < 0 {
|
||||
logger.error("mpv_render_context_render() failed with error code: \(result)")
|
||||
} else {
|
||||
logger.info("mpv_render_context_render() called successfully.")
|
||||
}
|
||||
mpv_render_context_render(OpaquePointer(mpvGL), ¶ms)
|
||||
}
|
||||
}
|
||||
|
||||
// Disable the scissor test after rendering if it was enabled
|
||||
if needsPartialUpdate() {
|
||||
glDisable(GLenum(GL_SCISSOR_TEST))
|
||||
}
|
||||
|
||||
// Clear dirty region after drawing
|
||||
clearDirtyRegion()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ struct PlayerBackendView: View {
|
||||
Color.clear
|
||||
.onAppear { player.playerSize = proxy.size }
|
||||
.onChange(of: proxy.size) { _ in player.playerSize = proxy.size }
|
||||
.onChange(of: player.controls.presentingOverlays) { _ in player.playerSize = proxy.size }
|
||||
.onChange(of: player.currentItem?.id) { _ in player.playerSize = proxy.size }
|
||||
})
|
||||
|
||||
#if !os(tvOS)
|
||||
|
||||
@@ -56,7 +56,6 @@ extension VideoPlayerView {
|
||||
player.seek.gestureStart = time
|
||||
}
|
||||
let timeSeek = (time / player.playerSize.width) * horizontalDrag * seekGestureSpeed
|
||||
|
||||
player.seek.gestureSeek = timeSeek
|
||||
}
|
||||
return
|
||||
@@ -80,6 +79,54 @@ extension VideoPlayerView {
|
||||
}
|
||||
}
|
||||
|
||||
var detailsDragGesture: some Gesture {
|
||||
DragGesture(minimumDistance: 30)
|
||||
.onChanged { value in
|
||||
handleDetailsDragChange(value)
|
||||
}
|
||||
.onEnded { value in
|
||||
handleDetailsDragEnd(value)
|
||||
}
|
||||
}
|
||||
|
||||
private func handleDetailsDragChange(_ value: DragGesture.Value) {
|
||||
let maxOffset = -player.playerSize.height
|
||||
|
||||
// Continuous drag update for smooth movement of VideoDetails
|
||||
if fullScreenDetails {
|
||||
// Allow only downward dragging when in fullscreen
|
||||
if value.translation.height > 0 {
|
||||
detailViewDragOffset = min(value.translation.height, abs(maxOffset))
|
||||
}
|
||||
} else {
|
||||
// Allow only upward dragging when not in fullscreen
|
||||
if value.translation.height < 0 {
|
||||
detailViewDragOffset = max(value.translation.height, maxOffset)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func handleDetailsDragEnd(_ value: DragGesture.Value) {
|
||||
if value.translation.height < -50, !fullScreenDetails {
|
||||
// Swipe up to enter fullscreen
|
||||
withAnimation(Constants.overlayAnimation) {
|
||||
fullScreenDetails = true
|
||||
detailViewDragOffset = 0
|
||||
}
|
||||
} else if value.translation.height > 50, fullScreenDetails {
|
||||
// Swipe down to exit fullscreen
|
||||
withAnimation(Constants.overlayAnimation) {
|
||||
fullScreenDetails = false
|
||||
detailViewDragOffset = 0
|
||||
}
|
||||
} else {
|
||||
// Reset offset if drag was not significant
|
||||
withAnimation(Constants.overlayAnimation) {
|
||||
detailViewDragOffset = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func onPlayerDragGestureEnded() {
|
||||
if horizontalPlayerGestureEnabled, isHorizontalDrag {
|
||||
isHorizontalDrag = false
|
||||
@@ -108,7 +155,6 @@ extension VideoPlayerView {
|
||||
}
|
||||
}
|
||||
|
||||
// Function to temporarily disable the toggle gesture after a fullscreen change
|
||||
private func disableGestureTemporarily() {
|
||||
disableToggleGesture = true
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
|
||||
|
||||
@@ -223,7 +223,7 @@ struct VideoDetails: View {
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.contentShape(Rectangle())
|
||||
.padding(.horizontal, 16)
|
||||
// swiftlint:disable trailing_closure
|
||||
|
||||
// TODO: when setting tvOS minimum to 16, the platform modifier can be removed
|
||||
#if !os(tvOS)
|
||||
.simultaneousGesture( // Simultaneous gesture to prioritize button tap
|
||||
@@ -234,7 +234,7 @@ struct VideoDetails: View {
|
||||
}
|
||||
)
|
||||
#endif
|
||||
// swiftlint:enable trailing_closure
|
||||
|
||||
if VideoActions().isAnyActionVisible() {
|
||||
VideoActions(video: player.videoForDisplay)
|
||||
.padding(.vertical, 5)
|
||||
|
||||
@@ -24,13 +24,12 @@ struct VideoPlayerView: View {
|
||||
#if os(macOS)
|
||||
335
|
||||
#else
|
||||
200
|
||||
140
|
||||
#endif
|
||||
}
|
||||
|
||||
@State private var playerSize: CGSize = .zero { didSet { updateSidebarQueue() } }
|
||||
@State private var hoveringPlayer = false
|
||||
@State private var fullScreenDetails = false
|
||||
@State private var sidebarQueue = defaultSidebarQueueValue
|
||||
|
||||
@Environment(\.colorScheme) private var colorScheme
|
||||
@@ -51,12 +50,14 @@ struct VideoPlayerView: View {
|
||||
@State var isHorizontalDrag = false
|
||||
@State var isVerticalDrag = false
|
||||
@State var viewDragOffset = Self.hiddenOffset
|
||||
@State var detailViewDragOffset: Double = 0
|
||||
// swiftlint:enable private_swiftui_state
|
||||
|
||||
#endif
|
||||
|
||||
// swiftlint:disable private_swiftui_state
|
||||
@State var disableToggleGesture = false
|
||||
@State var fullScreenDetails = false
|
||||
// swiftlint:enable private_swiftui_state
|
||||
|
||||
@ObservedObject var player = PlayerModel.shared // swiftlint:disable:this swiftui_state_private
|
||||
@@ -307,6 +308,8 @@ struct VideoPlayerView: View {
|
||||
#endif
|
||||
.id(player.currentVideo?.cacheKey)
|
||||
.transition(.opacity)
|
||||
.offset(y: detailViewDragOffset)
|
||||
.gesture(detailsDragGesture)
|
||||
} else {
|
||||
VStack {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user