Development around libVLC • Seeking around in m3u8 streaming



Hello all, this is my first time using VLCKit.
I’m doing a few tests to see if I got the gist of integrating it into a SwiftUI app, everything was working smoothly until I stumbled in an issue that for the life of me I cannot fix.
I’ve done a number of tests with a number of video format, but I’ve found 2 m3u8 sources that I simply cannot properly play, of better yet I cannot seek.
The two sources are:

  • https://bradmax.com/static/video/tos/440272.m3u8
  • https://bitdash-a.akamaihd.net/content/ … ylist.m3u8

They are just demo sources that I found around just to test my code.

I’ve created the simplest possible code to reproduce the issue, here it goes.

Code:

import SwiftUIimport VLCKitstruct ContentView: View { @StateObject private var viewModel = VideoPlayerViewModel() var body: some View { VStack { VideoPlayerView(player: viewModel.player) .frame(width: 400, height: 300) // Set your desired frame .onAppear { viewModel.setupPlayer() } Slider(value: $viewModel.seekTime, in: 0...viewModel.videoLength, onEditingChanged: { editing in viewModel.seekVideo(to: viewModel.seekTime) }) .padding() } }}class VideoPlayerViewModel: ObservableObject { @Published var player = VLCMediaPlayer() @Published var seekTime: Float = 0 var videoLength: Float { return (player.media?.length.value?.floatValue ?? 0) / 1000 } func setupPlayer() { let media = VLCMedia(url: URL(string: "https://bradmax.com/static/video/tos/440272.m3u8")!) player.media = media player.play() } func seekVideo(to time: Float) { let vlcTime = VLCTime(number: NSNumber(value: time * 1000)) player.time = vlcTime }}struct VideoPlayerView: NSViewRepresentable { let player: VLCMediaPlayer func makeNSView(context: Context) -> NSView { let view = NSView() player.drawable = view return view } func updateNSView(_ nsView: NSView, context: Context) { // Update the view if needed. }}

When I try to move the slider around to change position in the video stream, it doesn’t change the position and it starts playing back from where it was.
Sometimes it does change position, but not to where I move the slider, it’s all very strange.
I’ve tested the video stream with VLC 3.0.20 for macOS and I can successfully move around the timeline, which makes me thinking I’m doing something wrong in my code.
I’m using VLCKit 3.5.0.

Any idea what I might be doing wrong?

Statistics: Posted by rhaidiz — 17 May 2024 16:00