Skip to content

In-stream example migration #731

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

Merged
merged 2 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
import com.google.android.exoplayer2.upstream.DataSpec;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;

import org.prebid.mobile.Host;
import org.prebid.mobile.InStreamVideoAdUnit;
import org.prebid.mobile.PrebidMobile;
import org.prebid.mobile.Signals;
import org.prebid.mobile.Util;
import org.prebid.mobile.VideoParameters;
Expand All @@ -31,9 +29,13 @@

public class GamOriginalApiVideoInStream extends BaseAdActivity {

private static final String AD_UNIT_ID = "/5300653/test_adunit_vast_pavliuchyk";
private static final String CONFIG_ID = "1001-1";
private static final String STORED_RESPONSE = "sample_video_response";
private static final String AD_UNIT_ID = "/21808260008/prebid_demo_app_instream";
private static final String CONFIG_ID = "prebid-demo-video-interstitial-320-480-original-api";

private static final int WIDTH = 640;
private static final int HEIGHT = 480;

private static final String VIDEO_URL = "https://storage.googleapis.com/gvabox/media/samples/stock.mp4";

private InStreamVideoAdUnit adUnit;
private SimpleExoPlayer player;
Expand All @@ -45,15 +47,6 @@ public class GamOriginalApiVideoInStream extends BaseAdActivity {
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// The ID of Mocked Bid Response on PBS. Only for test cases.
PrebidMobile.setStoredAuctionResponse(STORED_RESPONSE);

// This example uses Rubicon Server TODO: Rewrite to AWS Server
PrebidMobile.setPrebidServerAccountId("1001");
PrebidMobile.setPrebidServerHost(
Host.createCustomHost("https://prebid-server.rubiconproject.com/openrtb2/auction")
);

createAd();
}

Expand All @@ -62,7 +55,7 @@ private void createAd() {
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 600);
getAdWrapperView().addView(playerView, params);

adUnit = new InStreamVideoAdUnit(CONFIG_ID, 640, 480);
adUnit = new InStreamVideoAdUnit(CONFIG_ID, WIDTH, HEIGHT);

VideoParameters parameters = new VideoParameters(Collections.singletonList("video/mp4"));
parameters.setProtocols(Collections.singletonList(Signals.Protocols.VAST_2_0));
Expand All @@ -72,7 +65,7 @@ private void createAd() {

adUnit.fetchDemand((resultCode, keysMap) -> {
HashSet<org.prebid.mobile.AdSize> sizes = new HashSet<>();
sizes.add(new org.prebid.mobile.AdSize(640, 480));
sizes.add(new org.prebid.mobile.AdSize(WIDTH, HEIGHT));
adsUri = Uri.parse(Util.generateInstreamUriForGam(AD_UNIT_ID, sizes, keysMap));

ImaAdsLoader.Builder imaBuilder = new ImaAdsLoader.Builder(this);
Expand All @@ -88,8 +81,7 @@ private void initializePlayer() {
playerView.setPlayer(player);
adsLoader.setPlayer(player);

Uri uri = Uri.parse("https://storage.googleapis.com/gvabox/media/samples/stock.mp4");
// Uri uri = Uri.parse("<![CDATA[https://storage.googleapis.com/gvabox/media/samples/stock.mp4]]>");
Uri uri = Uri.parse(VIDEO_URL);
MediaItem mediaItem = MediaItem.fromUri(uri);
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, getString(R.string.app_name));
ProgressiveMediaSource.Factory mediaSourceFactory = new ProgressiveMediaSource.Factory(dataSourceFactory);
Expand Down Expand Up @@ -120,14 +112,5 @@ protected void onDestroy() {
if (player != null) {
player.release();
}

// TODO: Return to AWS Server
PrebidMobile.setPrebidServerAccountId("0689a263-318d-448b-a3d4-b02e8a709d9d");
PrebidMobile.setPrebidServerHost(
Host.createCustomHost(
"https://prebid-server-test-j.prebid.org/openrtb2/auction"
)
);
PrebidMobile.setStoredAuctionResponse(null);
}
}
2 changes: 1 addition & 1 deletion Example/PrebidDemoJava/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<string name="gam_original_video_rewarded">GAM (Original API) Video Rewarded</string>
<string name="gam_original_native_in_app">GAM (Original API) Native In-App</string>
<string name="gam_original_native_styles">GAM (Original API) Native Styles</string>
<string name="gam_original_in_stream">GAM (Original API) In-Stream (Rubicon)</string>
<string name="gam_original_in_stream">GAM (Original API) In-Stream</string>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ import org.prebid.mobile.prebidkotlindemo.activities.BaseAdActivity
class GamOriginalApiInStreamActivity : BaseAdActivity() {

companion object {
const val AD_UNIT_ID = "/5300653/test_adunit_vast_pavliuchyk"
const val CONFIG_ID = "1001-1"
const val STORED_RESPONSE = "sample_video_response"
const val AD_UNIT_ID = "/21808260008/prebid_demo_app_instream"
const val CONFIG_ID = "prebid-demo-video-interstitial-320-480-original-api"

const val WIDTH = 640
const val HEIGHT = 480

const val VIDEO_URL = "https://storage.googleapis.com/gvabox/media/samples/stock.mp4"
}

private var adUnit: InStreamVideoAdUnit? = null
Expand All @@ -52,15 +54,6 @@ class GamOriginalApiInStreamActivity : BaseAdActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

// The ID of Mocked Bid Response on PBS. Only for test cases.
PrebidMobile.setStoredAuctionResponse(STORED_RESPONSE)

// This example uses Rubicon Server TODO: Rewrite to AWS Server
PrebidMobile.setPrebidServerAccountId("1001")
PrebidMobile.setPrebidServerHost(
Host.createCustomHost("https://prebid-server.rubiconproject.com/openrtb2/auction")
)

createAd()
}

Expand Down Expand Up @@ -116,15 +109,14 @@ class GamOriginalApiInStreamActivity : BaseAdActivity() {
}

private fun initializePlayer() {

adsLoader = ImaAdsLoader.Builder(this).build()

val playerBuilder = SimpleExoPlayer.Builder(this)
player = playerBuilder.build()
playerView!!.player = player
adsLoader!!.setPlayer(player)

val uri = Uri.parse("https://storage.googleapis.com/gvabox/media/samples/stock.mp4")
val uri = Uri.parse(VIDEO_URL)

val mediaItem = MediaItem.fromUri(uri)
val dataSourceFactory: DataSource.Factory = DefaultDataSourceFactory(this, getString(R.string.app_name))
Expand All @@ -148,15 +140,6 @@ class GamOriginalApiInStreamActivity : BaseAdActivity() {
adsLoader?.setPlayer(null)
adsLoader?.release()
player?.release()

// TODO: Return to AWS Server
PrebidMobile.setPrebidServerAccountId("0689a263-318d-448b-a3d4-b02e8a709d9d")
PrebidMobile.setPrebidServerHost(
Host.createCustomHost(
"https://prebid-server-test-j.prebid.org/openrtb2/auction"
)
)
PrebidMobile.setStoredAuctionResponse(null)
}

}