i am developing a SwiftUI tvOS app and using the TVVLCKit to download files and play them
i would like to use the already loaded media (video file) again as a preview small thumbnail when scrubbing,
i want a VLCMediaPlayer clone but to use the same already downloaded and parsed media object and just set the time to the scrubber time and show it in pause mode
any idea how to init another VLCMediaPlayer object with another VLCMedia object in SwiftUI ?
thanks
here is my code to load the first media:
Code: Select all
import SwiftUI
import AVFoundation
class VlcPlayerView: UIView, VLCMediaPlayerDelegate
{
let mediaPlayer: VLCMediaPlayer = VLCMediaPlayer()
let videoURLString: String = "https://upload.wikimedia.org/wikipedia/commons/transcoded/c/c0/Big_Buck_Bunny_4K.webm/Big_Buck_Bunny_4K.webm.480p.vp9.webm"
override init(frame: CGRect)
{
super.init(frame: frame)
mediaPlayer.media = VLCMedia(url: URL(string: videoURLString)!)
mediaPlayer.delegate = self
mediaPlayer.drawable = self
mediaPlayer.play()
}
public func stopPlayer()
{
mediaPlayer.stop()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func layoutSubviews() {
super.layoutSubviews()
}
}
Code: Select all
import SwiftUI
import AVFoundation
class VlcPreviewView: UIView, VLCMediaPlayerDelegate
{
let mediaPlayer: VLCMediaPlayer = VLCMediaPlayer()
override init(frame: CGRect)
{
super.init(frame: frame)
mediaPlayer.media = vlcPlayerViewInstance.mediaPlayer.media // <-- this is my question, how to do something like this ?
mediaPlayer.delegate = self
mediaPlayer.drawable = self
mediaPlayer.play()
mediaPlayer.media.time = vlcPlayerViewInstance.mediaPlayer.media.time // this line is working
mediaPlayer.pause()
}
public func stopPlayer()
{
mediaPlayer.stop()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func layoutSubviews() {
super.layoutSubviews()
}
}
what i aim to achieve: