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

Playing ads on AppleTV with PlayKit_IMA #26

Open
attilakiss323 opened this issue May 19, 2023 · 0 comments
Open

Playing ads on AppleTV with PlayKit_IMA #26

attilakiss323 opened this issue May 19, 2023 · 0 comments

Comments

@attilakiss323
Copy link

Description
I am using the PlayKit_IMA plugin to play pre-roll ads in our React Native TVos. The first time I open the video player the ad loads as expected, however if I then exit the player and open it again the ad does not load anymore. AdEvents.AD_REQUESTED is fired, but AdEvents.STARTED is not.

Setup

 player
      .setup(PLAYER_TYPE.OTT, JSON.stringify(playerOptions), partnerId)
      .then(() => {
         // ... Check if component is already mounted and destroy the player if it is
        player
          .loadMedia(assetId, JSON.stringify(mediaAsset))
          .then(() => {
              // ...
          })
          .catch((error: KalturaError) => {
              // ... Set the error to a global redux state
          })
      })
      .catch((error) => {
        // ... Set the error to a global redux state
      })

Where the initial config looks like this:

 const playerOptions = {
     serverUrl,
     ks,
     autoplay: true,
     plugins: {
       ima: {
         adTagUrl: getPreRollAdUrl(adBreaks),
         alwaysStartWithPreroll: true,
      }
    }
  }

Not sure if it is relevant for the config, but we are playing DRM protected videos.

Versions

 "react-native": "npm:[email protected]",
 "kaltura-player-rn": "0.4.2",

Gemfile:

ruby '3.0.0'
gem 'cocoapods', '~> 1.11', '>= 1.11.0'

Observation
As far as I can tell the issue is that in IMAPlugin.swift when the ad is loaded it is immediately discarded as well, but I haven't been able to figure out why.

      case .LOADED:
             // This if condition triggers when the player is opened for the second time
            if shouldDiscard(ad: event.ad, currentState: currentState) {
                self.discardAdBreak(adsManager: adsManager)
            } else {
                var adEvent = AdEvent.AdLoaded()
                
                if let ad = event.ad {
                    let adInfo = PKAdInfo(ad: ad,
                                          podCount: adsManager.adCuePoints.count,
                                          adPlayHead: .nan)
                    self.pkAdInfo = adInfo
                    adEvent = AdEvent.AdLoaded(adInfo: adInfo)
                }
                
                self.notify(event: adEvent)
                
                // if we have more than one ad don't start the manager, it will be handled in `AD_BREAK_READY`
                guard adsManager.adCuePoints.count == 0 else { return }
                guard canPlayAd(forState: currentState) else { return }
                self.start(adsManager: adsManager)
            }

Any suggestion would be highly appreciated.
Thank you!

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

No branches or pull requests

1 participant