androidreact-nativevideojwplayergoogle-ima

JWPlayer: Pre-roll ads are not playing on Android (Ad Error: 402, 20402)


I am using JWPlayer React Native SDK in my project, and I have a problem with pre-roll ads on Android. The ads do not play, and I get this error:

Ad Error: VAST media file loading reached a timeout of 8 seconds.
Code: 402, AdErrorCode: 20402

Use this configuration in a React Native project:

const jwConfig = {
  license: 'JWP_LICENSE', // Not required to reproduce the issue
  preload: 'auto',
  autostart: true,
  title: 'Single Inline Linear Preroll',
  playlist: [
    {
      title: 'Single Inline Linear Preroll',
      file: 'https://content.bitsontherun.com/videos/q1fx20VZ-52qL9xLP.mp4',
      adschedule: {
        adBreak1: {
          offset: 'pre',
          ad: {
            source: 'googima',
            tag: 'https://video.doubleverify.com/tester/fixtures/vast/vast3.xml',
          },
        },
      },
    },
  ],
  advertising: {
    client: 'googima',
  },
};

Set up build.gradle like this:

buildscript {
    ext {
        buildToolsVersion = "34.0.0"
        minSdkVersion = 21
        compileSdkVersion = 34
        targetSdkVersion = 34
        ndkVersion = "25.1.8937393"
        kotlinVersion = "1.8.0"
        RNJWPlayerUseGoogleIMA = true
    }
    repositories {
        google()
        mavenCentral()
        maven {
            url 'https://mvn.jwplayer.com/content/repositories/releases/'
        }
    }
    dependencies {
        classpath("com.android.tools.build:gradle")
        classpath("com.facebook.react:react-native-gradle-plugin")
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin")
    }

    allprojects {
        repositories {
            mavenLocal()
            google()
            mavenCentral()
            maven {
                url 'https://mvn.jwplayer.com/content/repositories/releases/'
            }
        }
    }
}

The pre-roll ad does not play. Check the logs, and you will see this error:

[DEBUG] onPlayerAdError:
{
  error: 'Ad Error: VAST media file loading reached a timeout of 8 seconds.',
  code: 402,
  adErrorCode: 20402,
  message: 'onPlayerAdError'
}

To test this issue, you can use this ready-to-run repository: jwplayer-ads-issue

I have tested with other valid ad tags and video files, but the problem remains the same. Does anyone know how to fix this issue?


Solution

  • I fixed this issue by setting backgroundAudioEnabled: true in jwConfig.

    The problem was caused by the missing flag in the configuration. The documentation is lacking in this regard, and the Example player did not have this flag either.

    const jwConfig = {
      ...
      backgroundAudioEnabled: true,
    };
    

    After adding this, pre-roll ads started working correctly.