kaltura / playkit-ios-ima

GNU Affero General Public License v3.0
3 stars 9 forks source link

Playing ads on AppleTV with kaltura-player-rn #66

Open attilakiss323 opened 1 year ago

attilakiss323 commented 1 year ago

Description I am using the PlayKit_IMA plugin to play pre-roll ads in our React Native TVos project with kaltura-player-rn. 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:react-native-tvos@0.69.6-0",
 "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!

giladna commented 1 year ago

Please check it on our samples if you see the same

https://github.com/kaltura/kaltura-player-ios-samples

attilakiss323 commented 1 year ago

@giladna Thanks for the reply! We have looked into the examples as you suggested, but we haven't managed to find a solution so far.

Do you maybe have an example implementation with pre-roll ads for react-native-tvos ?

I will try to provide some more context to the errors that we are getting:

Do you have an idea what could the issue be?

And my last question is could you point us towards a documentation on how to add mid-roll ads? Ideally with the PlayKit_IMA plugin.

x-NR-x commented 1 year ago

Hi @attilakiss323,

Sorry for the late reply. On which iOS version are you testing and getting theses errors? If you are using Xcode then I would like to get the version for that as well please. I'm asking because we are facing the "TypeError: undefined is not an object" in other places as well.

Thanks, Nilit Danan