Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TVVLCKit Implementation SwiftUI

I need to implement the VLC library in one of my TVOS applications, what I have currently is the following:

import SwiftUI
import TVVLCKit

struct VlcPlayerDemo: UIViewRepresentable{
    func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext<VlcPlayerDemo>) {
    }

    func makeUIView(context: Context) -> UIView {
        return PlayerUIView(frame: .zero)
    }
}

class PlayerUIView: UIView, VLCMediaPlayerDelegate {
  private let mediaPlayer = VLCMediaPlayer()

  override init(frame: CGRect) {
    super.init(frame: frame)

    let url = URL(string: "URL")!

    mediaPlayer.media = VLCMedia(url: url)
    mediaPlayer.delegate = self
    mediaPlayer.drawable = self
    mediaPlayer.play()
  }

  required init?(coder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
  }

  override func layoutSubviews() {
    super.layoutSubviews()
  }
}

This code works and plays the content correctly, but I need to play it in full screen and have controls to pause, play and track selectors as AVPlayer has them.

AVPlayer Example

like image 945
Fabian Reyes Avatar asked Dec 27 '25 19:12

Fabian Reyes


1 Answers

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

like image 111
Shaybc Avatar answered Dec 31 '25 00:12

Shaybc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!