Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
stefanosn opened this issue Jul 4, 2024 · 0 comments
Open

Comments

@stefanosn
Copy link

stefanosn commented Jul 4, 2024

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...
            }
        }
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant