Skip to content

VideoPlayer .onStateChanged { case .playing: } not called every time #65

Open
@stefanosn

Description

@stefanosn

Hello sir. I have implemented a collection view. In each cell i have this code from your example. When i scroll to each cell i load a url in the VideoPlayer. For some reason sometimes the case .playing(let totalDuration): is not called so i can not show the progress bar at my project because i do not have the totalDuration. Although is not triggered the video starts playing. The only way i found to show the progress bar is to pause the video and then play it after it starts playing to trigger the .playing(let totalDuration) and show the progress bar.

Do you have any clue why this might be happening or any idea how to overcome this issue in SwiftUI?
Is it an issue in the GSPlayer you think?
Any help appreciated sir.

struct ContentView : View {
@State private var autoReplay: Bool = true
@State private var mute: Bool = false
@State private var play: Bool = true
@State private var time: CMTime = .zero

var body: some View {
    VideoPlayer(url: someVideoURL, play: $play, time: $time)
        .autoReplay(autoReplay)
        .mute(mute)
        .onBufferChanged { progress in
            // Network loading buffer progress changed
        }
        .onPlayToEndTime { 
            // Play to the end time.
        }
        .onReplay { 
            // Replay after playing to the end. 
        }
        .onStateChanged { state in 
            switch state {
            case .loading:
                // Loading...
            case .playing(let totalDuration):
                // Playing...
            case .paused(let playProgress, let bufferProgress):
                // Paused...
            case .error(let error):
                // Error...
            }
        }
}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions