Vlckit with Swiftui

TVVLCKit Implementation SwiftUI

all you have to do is add a ZStack layer on-top of the VLC player and add your info and interactions there,

i have a written a full working code example with TVVLCKit and SwiftUI fro Apple-Tv on github that demonstrate how to add play pause and thumbmail control, a metadata info panel (as a place holder you can fill there what ever you want)

https://github.com/shaybc/VLCTester

hope this help more

How to show my AVPlayer in a VStack with SwiftUI

Thanks to Bogdan for the quick answer and for the like to the tutorial!

Here is the code, converted to NSView so it could work for macOS apps...

Here is the struct PlayerView :

struct PlayerView: NSViewRepresentable {
func updateNSView(_ nsView: NSView, context: NSViewRepresentableContext<PlayerView>) {

}
func makeNSView(context: Context) -> NSView {
return PlayerNSView(frame: .zero)
}
}

Here is the class, "the meat" like Bogdan said:

class PlayerNSView: NSView{
private let playerLayer = AVPlayerLayer()

override init(frame:CGRect){
super.init(frame: frame)
let urlVideo = URL(string: "https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8")!
let player = AVPlayer(url: urlVideo)
player.play()
playerLayer.player = player
if layer == nil{
layer = CALayer()
}
layer?.addSublayer(playerLayer)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func layout() {
super.layout()
playerLayer.frame = bounds
}
}

Finally you can use PlayerView() to add the AVPlayer in the struct ContentView.



Related Topics



Leave a reply



Submit