Identify buffering state of MPMoviePlayerController in SWIFT

239 views Asked by At

Using below code to identify when video buffering and when playing. Video starts and gets paused and buffering. Need to show loader when buffering and remove when starts playing. Tried two ways but not properly worked.

if moviePlayer.loadState == MPMovieLoadState.Playable
    {
            print("playable")
        MBProgressHUD.hideAllHUDsForView(self.view, animated: true)
        print(moviePlayer.loadState)
    }
    if moviePlayer.loadState == MPMovieLoadState.PlaythroughOK
    {
        print("playable ok")
        MBProgressHUD.hideAllHUDsForView(self.view, animated: true)
        print(moviePlayer.loadState)
    }
    if moviePlayer.loadState == MPMovieLoadState.Stalled
    {
        print("stalled")
        print(moviePlayer.loadState)
    }
    if moviePlayer.loadState == MPMovieLoadState.Unknown
    {
        print("unknown")
        print(moviePlayer.loadState)

    }

Second way tried is:

if moviePlayer.playbackState == MPMoviePlaybackState.Stopped
    {
        print("stopped")
    }
    if moviePlayer.playbackState == MPMoviePlaybackState.Paused
    {
        print("paused")
         MBProgressHUD.hideAllHUDsForView(self.view, animated: true)

    }
    if moviePlayer.playbackState == MPMoviePlaybackState.Playing
    {
        print("playing")
         MBProgressHUD.hideAllHUDsForView(self.view, animated: true)

    }
    if moviePlayer.playbackState == MPMoviePlaybackState.Interrupted
    {
        print("interrupt")
    }
    if moviePlayer.playbackState == MPMoviePlaybackState.SeekingForward
    {
        print("SeekingForward")
    }
    if moviePlayer.playbackState == MPMoviePlaybackState.SeekingBackward
    {
        print("SeekingBackward")
    }

And also wants to know what is loadState.rawValue 1,3 and 5. This also comes when print in console.

Please guide.

0

There are 0 answers