mirror of
https://github.com/yattee/yattee.git
synced 2024-12-22 21:43:41 +00:00
Minor improvements
This commit is contained in:
parent
590aa00148
commit
67723f4624
@ -183,11 +183,6 @@ final class AVPlayerBackend: PlayerBackend {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
func updateControls() {}
|
|
||||||
func startControlsUpdates() {}
|
|
||||||
func stopControlsUpdates() {}
|
|
||||||
func setNeedsDrawing(_: Bool) {}
|
|
||||||
|
|
||||||
private func loadSingleAsset(
|
private func loadSingleAsset(
|
||||||
_ url: URL,
|
_ url: URL,
|
||||||
stream: Stream,
|
stream: Stream,
|
||||||
@ -564,4 +559,10 @@ final class AVPlayerBackend: PlayerBackend {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func updateControls() {}
|
||||||
|
func startControlsUpdates() {}
|
||||||
|
func stopControlsUpdates() {}
|
||||||
|
func setNeedsDrawing(_: Bool) {}
|
||||||
|
func setSize(_: Double, _: Double) {}
|
||||||
}
|
}
|
||||||
|
@ -152,6 +152,10 @@ final class MPVBackend: PlayerBackend {
|
|||||||
isPlaying = true
|
isPlaying = true
|
||||||
startClientUpdates()
|
startClientUpdates()
|
||||||
|
|
||||||
|
if controls.presentingControls {
|
||||||
|
startControlsUpdates()
|
||||||
|
}
|
||||||
|
|
||||||
client?.play()
|
client?.play()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -305,4 +309,8 @@ final class MPVBackend: PlayerBackend {
|
|||||||
func setNeedsDrawing(_ needsDrawing: Bool) {
|
func setNeedsDrawing(_ needsDrawing: Bool) {
|
||||||
client?.setNeedsDrawing(needsDrawing)
|
client?.setNeedsDrawing(needsDrawing)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setSize(_ width: Double, _ height: Double) {
|
||||||
|
self.client?.setSize(width, height)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -168,14 +168,23 @@ final class MPVClient: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setSize(_ width: Double, _ height: Double) {
|
func setSize(_ width: Double, _ height: Double) {
|
||||||
logger.info("setting player size to \(width),\(height)")
|
let roundedWidth = width.rounded()
|
||||||
#if !os(macOS)
|
let roundedHeight = height.rounded()
|
||||||
guard width <= UIScreen.main.bounds.width, height <= UIScreen.main.bounds.height else {
|
|
||||||
logger.info("requested size is greater than screen size, ignoring")
|
guard width > 0, height > 0 else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
glView?.frame = CGRect(x: 0, y: 0, width: width, height: height)
|
logger.info("setting player size to \(roundedWidth),\(roundedHeight)")
|
||||||
|
#if !os(macOS)
|
||||||
|
guard roundedWidth <= UIScreen.main.bounds.width, roundedHeight <= UIScreen.main.bounds.height else {
|
||||||
|
logger.info("requested size is greater than screen size, ignoring")
|
||||||
|
logger.info("width: \(roundedWidth) <= \(UIScreen.main.bounds.width)")
|
||||||
|
logger.info("height: \(roundedHeight) <= \(UIScreen.main.bounds.height)")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
glView?.frame = CGRect(x: 0, y: 0, width: roundedWidth, height: roundedHeight)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,6 +50,7 @@ protocol PlayerBackend {
|
|||||||
func stopControlsUpdates()
|
func stopControlsUpdates()
|
||||||
|
|
||||||
func setNeedsDrawing(_ needsDrawing: Bool)
|
func setNeedsDrawing(_ needsDrawing: Bool)
|
||||||
|
func setSize(_ width: Double, _ height: Double)
|
||||||
}
|
}
|
||||||
|
|
||||||
extension PlayerBackend {
|
extension PlayerBackend {
|
||||||
|
@ -101,6 +101,10 @@ final class PlayerControlsModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func resetTimer() {
|
func resetTimer() {
|
||||||
|
if !presentingControls {
|
||||||
|
show()
|
||||||
|
}
|
||||||
|
|
||||||
removeTimer()
|
removeTimer()
|
||||||
timer = Timer.scheduledTimer(withTimeInterval: 5.0, repeats: false) { _ in
|
timer = Timer.scheduledTimer(withTimeInterval: 5.0, repeats: false) { _ in
|
||||||
withAnimation(PlayerControls.animation) { [weak self] in
|
withAnimation(PlayerControls.animation) { [weak self] in
|
||||||
|
@ -42,7 +42,9 @@ final class PlayerModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Published var playerSize: CGSize = .zero
|
@Published var playerSize: CGSize = .zero { didSet {
|
||||||
|
backend.setSize(playerSize.width, playerSize.height)
|
||||||
|
}}
|
||||||
@Published var stream: Stream?
|
@Published var stream: Stream?
|
||||||
@Published var currentRate: Float = 1.0 { didSet { backend.setRate(currentRate) } }
|
@Published var currentRate: Float = 1.0 { didSet { backend.setRate(currentRate) } }
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ extension PlayerModel {
|
|||||||
|
|
||||||
func rebuildTVMenu() {
|
func rebuildTVMenu() {
|
||||||
#if os(tvOS)
|
#if os(tvOS)
|
||||||
controller?.playerView.transportBarCustomMenuItems = [
|
avPlayerBackend.controller?.playerView.transportBarCustomMenuItems = [
|
||||||
restoreLastSkippedSegmentAction,
|
restoreLastSkippedSegmentAction,
|
||||||
rateMenu,
|
rateMenu,
|
||||||
streamsMenu
|
streamsMenu
|
||||||
|
@ -1,18 +1,22 @@
|
|||||||
import GLKit
|
import GLKit
|
||||||
|
import Logging
|
||||||
import OpenGLES
|
import OpenGLES
|
||||||
|
|
||||||
final class MPVOGLView: GLKView {
|
final class MPVOGLView: GLKView {
|
||||||
|
private var logger = Logger(label: "stream.yattee.mpv.oglview")
|
||||||
private var defaultFBO: GLint?
|
private var defaultFBO: GLint?
|
||||||
|
|
||||||
var mpvGL: UnsafeMutableRawPointer?
|
var mpvGL: UnsafeMutableRawPointer?
|
||||||
var needsDrawing = true
|
var needsDrawing = true
|
||||||
|
|
||||||
override init(frame: CGRect) {
|
override init(frame: CGRect) {
|
||||||
guard let context = EAGLContext(api: .openGLES2) else {
|
guard let context = EAGLContext(api: .openGLES3) else {
|
||||||
print("Failed to initialize OpenGLES 2.0 context")
|
print("Failed to initialize OpenGLES 2.0 context")
|
||||||
exit(1)
|
exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.info("frame size: \(frame.width) x \(frame.height)")
|
||||||
|
|
||||||
super.init(frame: frame, context: context)
|
super.init(frame: frame, context: context)
|
||||||
contentMode = .redraw
|
contentMode = .redraw
|
||||||
|
|
||||||
@ -33,14 +37,17 @@ final class MPVOGLView: GLKView {
|
|||||||
glClear(UInt32(GL_COLOR_BUFFER_BIT))
|
glClear(UInt32(GL_COLOR_BUFFER_BIT))
|
||||||
}
|
}
|
||||||
|
|
||||||
override func draw(_ rect: CGRect) {
|
override func draw(_: CGRect) {
|
||||||
glGetIntegerv(UInt32(GL_FRAMEBUFFER_BINDING), &defaultFBO!)
|
glGetIntegerv(UInt32(GL_FRAMEBUFFER_BINDING), &defaultFBO!)
|
||||||
|
|
||||||
|
var dims: [GLint] = [0, 0, 0, 0]
|
||||||
|
glGetIntegerv(GLenum(GL_VIEWPORT), &dims)
|
||||||
|
|
||||||
if mpvGL != nil {
|
if mpvGL != nil {
|
||||||
var data = mpv_opengl_fbo(
|
var data = mpv_opengl_fbo(
|
||||||
fbo: Int32(defaultFBO!),
|
fbo: Int32(defaultFBO!),
|
||||||
w: Int32(rect.size.width) * Int32(contentScaleFactor),
|
w: Int32(dims[2]),
|
||||||
h: Int32(rect.size.height) * Int32(contentScaleFactor),
|
h: Int32(dims[3]),
|
||||||
internal_format: 0
|
internal_format: 0
|
||||||
)
|
)
|
||||||
var flip: CInt = 1
|
var flip: CInt = 1
|
||||||
|
Loading…
Reference in New Issue
Block a user