Skip to content

No duration for ogg files

Hello,

This is the code that I use to setup VLCMediaPlayer:

    let mediaPlayer = VLCMediaPlayer()

    func loadMedia(url: URL) {
         let media = VLCMedia(url: url)
         self?.mediaPlayer.media = media
         self?.mediaPlayer.play()
    }

    var durationInMilliseconds: Float {
        guard let lengthInMilliseconds = mediaLength?.intValue else {
            return 0
        }
        return Float(lengthInMilliseconds)
    }

    private var mediaLength: VLCTime? {
        guard let length = self.mediaPlayer.media?.length else {
            return nil
        }
        return length
    }

This is the function that I call every 0.2 seconds to update current slider position (progress view) and current time. I have added "@#@ duration" marker to show duration of the audioFile.

    func currentPositionValue() -> Float {
        let currentTimeInMilliseconds = Float(mediaPlayer.time.intValue)
        let currSliderPositionValue = currentTimeInMilliseconds / durationInMilliseconds * 100 //durationInMilliseconds is 0.
        
        print("@#@ Duration: \(durationInMilliseconds)") //This is the audio file duration
        return currSliderPositionValue
    }

This is the duration value for '9seconds_with_duration.ogg' file:

This is the duration value for '4seconds_no_duration.ogg' file:

I have tested different ogg files, for some VLCPlayer shows duration, for others it does not.

Here are 2 metadata values for 2 files. Both of them have duration, bitrate and filesize.

File '9seconds_with_duration.ogg' info:

File '4seconds_no_duration.ogg' info:

Audio files:

4seconds_no_duration

9seconds_with_duration

Please, tell us if you need any more information.

Thank you.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information