TVVLCKit, is it possible to use the same VLCMedia object twice ?

iOS, iPad, iPhone, tvOS specific usage questions
shaybc
Blank Cone
Blank Cone
Posts: 39
Joined: 27 Mar 2016 13:59

TVVLCKit, is it possible to use the same VLCMedia object twice ?

Postby shaybc » 17 Sep 2021 16:10

hi,

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() } }
and this is how i would like to clone the preview object (conceptual code):

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:

Image

bubu?
Developer
Developer
Posts: 371
Joined: 20 Jun 2017 15:29
Operating System: macOS, iOS

Re: TVVLCKit, is it possible to use the same VLCMedia object twice ?

Postby bubu? » 17 Sep 2021 17:24

Hello,

This is a feature which is quite frequently asked, and we would like to develop it internally in our libraries to distribute it in every platform in the future.

Sadly, it isn't a priority for now.

Theoretically, this approach should be working by using the media(in most cases). You should know that it will probably be quite resource consuming.
You should be able to set the media from the `VLCMediaPlayer` instance.

Something in the lines of:

Code: Select all

newMediaPlayer.media = mediaPlayer.media
Hope it helps!
Soomin Lee - bubu

shaybc
Blank Cone
Blank Cone
Posts: 39
Joined: 27 Mar 2016 13:59

Re: TVVLCKit, is it possible to use the same VLCMedia object twice ?

Postby shaybc » 17 Sep 2021 17:34

hey bubu,
thanks for the reply, i already done what you are suggesting (this is exactly what i wrote in my example code), it compiles and it works, but ever since i made that change i am hunting for leaks and trying to understand what is eating the AppleTV resources, the app started crashing only because of this approach, if i reload the whole video from url from scratch everything works fine, but the optimization is shot to hell

so i was looking for a working code sample, thinking everybody already do this, so there is probably plethora of working code examples, (if people would care to share),

thanks for trying

shaybc
Blank Cone
Blank Cone
Posts: 39
Joined: 27 Mar 2016 13:59

Re: TVVLCKit, add video progress-bar & thumbnail

Postby shaybc » 18 Sep 2021 14:45

so i solved my problem, it was a memory leak from the 'NotificationCenter.default.addObserver' call, it set a value to a global @ObservableObject in the callback function and for some reason it caused a leak,

i turned my player into the @ObservableObject that holds the player state values and that fixed the problem,

i have uploaded my code in SwiftUI for tvOS and Apple-T, as a working github project,
you can use it as an example, though it does not suffer from performance issues (beside network latency that was not managed in the example) or memory leak, i suggest to use it as a demo and not for production

example code project: https://github.com/shaybc/VLCTester

bubu?
Developer
Developer
Posts: 371
Joined: 20 Jun 2017 15:29
Operating System: macOS, iOS

Re: TVVLCKit, is it possible to use the same VLCMedia object twice ?

Postby bubu? » 20 Sep 2021 13:52

Great, glad to hear that you solved the issue!

Thank you for the updates, and the link!
Soomin Lee - bubu

bosse
New Cone
New Cone
Posts: 1
Joined: 24 Dec 2021 03:58

Re: TVVLCKit, is it possible to use the same VLCMedia object twice ?

Postby bosse » 24 Dec 2021 04:12

Thanks for the github link. I’ve been struggling just getting a build going. It’ll help me understand what I’m missing.


Return to “VLC for iOS, iPadOS and Apple TV”

Who is online

Users browsing this forum: No registered users and 9 guests