I am trying to use VLCKit / TVVLCKit on an iOS/tvOS project.
I would like to be able to scan through a list of VLCMedia items and identify the length (duration) of the video file ahead of time, prior to playing the videos.
I am first ensuring each item is parsed with the following:
Code: Select all
media.parse(withOptions: VLCMediaParsingOptions(VLCMediaFetchNetwork))
Code: Select all
mediaDidFinishParsing
Code: Select all
media.length
Code: Select all
media.length.verboseStringValue
However, if I take a VLCMedia item, play it, and then check the length, I then see the correct duration. This works:
Code: Select all
let mediaList = VLCMediaList()
mediaList.add(media)
vpc.playMediaList(mediaList, firstIndex: 0, subtitlesFilePath: nil)
navigationController?.show(VLCFullscreenMovieTVViewController.init(), sender: nil)
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
NSLog("this item length: \(media.length.verboseStringValue)")
}
I've also attempted using lengthWait prior to playing the file like so:
Code: Select all
let length = media.lengthWait(until: Date().addingTimeInterval(10.0))
Ultimately my question is:
I'd like to know if there are any other strategies to identifying a VLCMedia item's length/duration without actually playing the file. It seems the length info is only available after loading the file to play, calling
Code: Select all
media.parse(withOptions:
Code: Select all
media.lengthWait(until:
If I need to "queue" up the item to play it, without actually playing it, to get the length info, I could potentially work with that. I only need to do this once when adding a file to my app's "library" and I can store the value. It seems like "media.lengthWait(until:" should be what I need, but even adding a very long wait time doesn't seem to produce a result for me.
Please let me know if there are any other strategies to get a media item's length value without actually playing it. I'd really appreciate it!
Thank you.