1

I'm trying to incorporate MobileVLCKit into my app but the default time observer isn't precise enough for me and makes the progress bar jump between times. Is there a way to get more precise time updates (for example, every 1/60th second)?

Here's my current code:

let player = VLCMediaPlayer()

func mediaPlayerTimeChanged(_ aNotification: Notification) {
    print(player.time)
}

/// 0.0
/// 0.0
/// 0.0
/// 0.1
/// 0.1
/// 0.1
/// 0.2

Thanks in advance!

ADB
  • 591
  • 7
  • 21

3 Answers3

0

Unable to find documentation for the option, I happened upon the following when browsing manually, which appears to be the solution to ensure not only that mediaPlayerTimeChanged updates more frequently, but the correct updated time of the playing media is accurate.

mediaPlayer.timeChangeUpdateInterval = 0.05

ballade4op52
  • 2,142
  • 5
  • 27
  • 42
0

you can use this solution:

    func setUpTimer() {
        Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { _ in
            self.progressAnimation()
        }
    }

    func progressAnimation() {
        UIView.animate(withDuration: 0.003, delay: 0.0, options: [.beginFromCurrentState],
                       animations: { [weak self] in
            self?.progressView.progress = player.position
            self?.layoutIfNeeded()
        }, completion: nil)
    }

call the setUpTimer() funtion on whatever you want fire

Maziar Saadatfar
  • 1,286
  • 1
  • 5
  • 11
  • Thank you for the reply. As I found a solution to this problem (posted as an answer below), and can't test your code now, I'll award you the bounty if you lead me to the solution regarding another VLCkit issue. For some reason lately, when I try to play a video, I'm getting a "EXC_BAD_ACCESS" crash, which is occurring (after finishing a short video or starting a longer video) on a thread called `0_HandleMediaPlayerTrackChanged_block_invoke` for the short and 'length changed' thread for the long. Could this relate to selector implementation? If so, can you show me how you're implementing them – ballade4op52 May 03 '23 at 00:21
  • @ballade4op52 URW, I didn't catch your issue, but: func seekTo(position: Float) {player.position = position},func seekTo(time: Float) {player.time = VLCTime(int: Int32(time * 1000))} – Maziar Saadatfar May 03 '23 at 09:09
-1

try: player.position

e.g:

let player = VLCMediaPlayer()

func mediaPlayerTimeChanged(_ aNotification: Notification) {
    print(player.position)
}

You need to get the content length too to convert it into a human readable time e.g: let content_length = player.media.length