SvenTiigi / YouTubePlayerKit

A Swift Package to easily play YouTube videos 📺
https://sventiigi.github.io/YouTubePlayerKit/
MIT License
714 stars 64 forks source link

Handle YouTube's native "An error occurred." #99

Closed artistbuddy closed 2 months ago

artistbuddy commented 3 months ago

Is your feature request related to a problem?

If URL is not a YouTube one or we persisted some URL and later YouTube deleted such a video, the player state remains ready, but YouTube's native splash screen says error.

Screenshot 2024-07-31 at 21 37 05

What solution would you like?

Catch YouTube's native error as player's state error.

What alternatives have you considered?

I have considered observing getInformation() or getPlaybackMetadata() somehow. If fails it means some error on YouTube side occurred.

Any additional context?

No response

acosmicflamingo commented 3 months ago

@SvenTiigi can this be fixed with the PR I had opened recently?

SvenTiigi commented 2 months ago

Hi @artistbuddy,

please check out the develop branch and let me know if this resolves your issue.

artistbuddy commented 2 months ago

@SvenTiigi yes, if video is unavailable or private the Player set its state to error (err 6).

btw. Now, because of @MainActor it isn't possible to initialise YouTubePlayer with default argument

@MainActor
final class YouTubePlayerAdapter {
    let player: YouTubePlayer

    // Call to main actor-isolated initializer 'init(source:configuration:)' in a synchronous nonisolated context
    init(player: YouTubePlayer = .init()) {
        self.player = player
    }
}

I think this is Swift limitation not a https://github.com/SvenTiigi/YouTubePlayerKit/pull/98 problem.

acosmicflamingo commented 2 months ago

I'm surprised I didn't see a compilation error when I worked on that PR 😕

SvenTiigi commented 2 months ago

@artistbuddy thanks for the response! Great to hear you are now receiving an error when passing a a YouTube video url which points to an unavailable or private video.

FYI: The @MainActor annotations have been removed

@acosmicflamingo I will implement the Swift 6 complete concurrency checks in a separate feature branch.

acosmicflamingo commented 2 months ago

@SvenTiigi sounds good!