Skip to main content

Getting Started

Instream video ads are video ad formats that play while users watch content. This guide explains how to integrate instream video ads using the GFP SDK.


Before You Begin

  • You need an Ad Unit ID to call ads.
    • Please complete the process of setting up ad providers, inventory settings, and ad unit registration through GFP Admin.
    • Please contact the GFP administrator for related information.
  • If there are other Views that overlay ads, exposure measurement may not work properly in some cases, which may adversely affect performance indicator measurement.

[Step 1] Complete GFP SDK Integration

Please refer to Getting Started.

The following content assumes that GFP SDK integration is complete.


[Step 2] Add Dependencies to App-Level build.gradle

To apply instream video ads, you need to add dependencies to the app-level build.gradle file as shown below.

build.gradle.kts
dependencies {
// Import the BoM for the GFP platform
implementation(platform("com.naver.gfpsdk:gfpsdk-bom:8.13.0"))

implementation("com.naver.gfpsdk:gfpsdk-core")
implementation("com.naver.gfpsdk.mediation:ndavideo")

// Optional: Add the dependencies for any other mediation libraries you want to use
// For example, add the mediation library dependencies for Google IMA
implementation("com.naver.gfpsdk:mediation:ima")
...
}

[Step 3] Add ViewGroup for Player Layout

To serve video ads, you first need to add a ViewGroup for the area where video ads and main content can be played to the layout of the Activity or Fragment where you want to serve ads.

In the example below, a Layout for video ads is declared with the id video_ad_container in a RelativeLayout ViewGroup.

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<!-- Video ad container -->
<RelativeLayout
android:id="@+id/video_ad_container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#000000"
app:layout_constraintDimensionRatio="16:9"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

[Step 4] Create Player and Ad UI Layout

Declare a layout that includes the Player (implementation of AdVideoPlayer must be provided) and ad UI needed for video ad playback.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<!-- Actual video player view (replace with player used by your service) -->
<com.naver.gfpsdk.adssample.video.SampleExoPlayerView
android:id="@+id/ad_video_player"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true" />

<!-- Ad UI container (skip button, progress bar, etc.) -->
<FrameLayout
android:id="@+id/ad_ui_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<!-- SMR ad reminder ad area -->
<FrameLayout
android:id="@+id/outer_text_ad_container"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>

[Step 5] Create AdParam and VideoAdScheduleParam

val adParam = AdParam.Builder().build()

val contentDuration = 653L // Content video length in seconds
val adScheduleId = "NDP_ADSCHDL" // Must be provided by GFP representative
val videoAdScheduleParam = VideoAdScheduleParam.Builder(adScheduleId)
.setDuration(contentDuration)
.setAdSchedulePolicy(true, false, true)
.setAdNoticeDurationSec(5)
.build()

[Step 6] Create and Configure GfpVideoAdScheduleManager

// Create manager
videoAdScheduleManager = GfpVideoAdScheduleManager(
this,
videoAdScheduleParam,
adParam,
adVideoPlayer,
adUiContainer
)

// Set video options
val videoAdOptions = GfpVideoAdOptions().apply {
supportedStreamingHLS = false
bitrateKbps = -1
videoLoadTimeout = 5000
}
videoAdScheduleManager.setVideoAdOptions(videoAdOptions)

[Step 7] Set Event Listeners

Set up schedule events and ad event listeners.

// Set schedule listener
videoAdScheduleManager.setAdScheduleListener(object: VideoAdScheduleListener {
override fun onScheduleLoaded(schedule: VideoScheduleResponse) {
// Ad schedule loaded successfully
}
override fun onContentResumeRequest() {
// Resume content
}
override fun onContentPauseRequest() {
// Pause content
}
override fun onScheduleCompleted() {
// All ads playback completed
}
override fun onError(error: GfpError) {
// Ad request failed
}
})

// Set ad event listener
videoAdScheduleManager.setAdListener(object: VideoAdListener {
override fun onAdLoaded(ad: GfpVideoAd) {
// Ad loaded successfully
}
override fun onAdStartReady(ad: GfpVideoAd) {
ad.start(true)
// Ad playback ready
}
// ... other events
})

[Step 8] Load Ads and Manage Lifecycle

// Load ads
videoAdScheduleManager.load()

// Lifecycle management
override fun onPause() {
super.onPause()
if (::videoAdScheduleManager.isInitialized) {
videoAdScheduleManager.pause()
}
}

override fun onDestroy() {
super.onDestroy()
if (::videoAdScheduleManager.isInitialized) {
videoAdScheduleManager.destroy()
}
}

AdVideoPlayer Implementation

The Player that will play video ads is injected in the form of the player used by the service. The service's player must implement the AdVideoPlayer interface.

For detailed implementation examples, please refer to Instream Video Ad Options.