如何在 ExoPlayer 中显示广告标记?
How to show ad markers in ExoPlayer?
我正在使用 ExoPlayer
2.7.1。我必须在特定时间间隔展示广告。这些间隔在一个以毫秒为单位的 longs 数组中。如何在 ExoPlayer 控制器中显示广告标记?
要集成您自己的广告解决方案,我通常建议查看 ExoPlayer 库的 AdsMediaSource and the AdsLoader,它提供了将您的广告很好地集成到内容媒体源中的方法。这样播放器就会知道广告播放并确保不能跳过广告、显示标记等。
AdsMediaSource 用于实现 ExoPlayer 的 IMA extension,但您可以利用这些作为您的解决方案。
回答您关于广告标记的具体问题:
PlayerControlView
有一个方法可以让您设置广告标记位置和布尔值以指示广告是否已显示:
playerControlView.setExtraAdGroupMarkers(
new long[]{10 * 1000, 120 * 1000},
new boolean[]{false, false});
但是,如果您使用的是 PlayerView out-of-the-box,则访问播放器视图以编程方式插入的 PlaybackControlView 会有点困难。因此,您不能使用 findById,而且恐怕 PlayerView 没有为控制器提供 getter。
因此,如果您正在使用 PlayerView,我看到的唯一方法是提供您自己的布局文件 exo_player_view.xml,您可以在其中设置自定义控制器:
在你的项目中创建一个文件res/layout/exo_player_view.xml并将layout file from here复制到其中。
在此布局文件中搜索 ID 为 exo_controller_placeholder 的视图元素。用这个元素替换它:
<com.google.android.exoplayer2.ui.PlayerControlView android:id="@id/exo_controller"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
在onCreate中查找player control view:
playerControlView = findViewById(R.id.exo_controller);
每当你想更新你调用的标记时:
playerControlView.setExtraAdGroupMarkers(
new long[]{10 * 1000, 120 * 1000},
new boolean[]{true, false});
第二个参数可让您将广告标记为所示。
我正在使用 ExoPlayer
2.7.1。我必须在特定时间间隔展示广告。这些间隔在一个以毫秒为单位的 longs 数组中。如何在 ExoPlayer 控制器中显示广告标记?
要集成您自己的广告解决方案,我通常建议查看 ExoPlayer 库的 AdsMediaSource and the AdsLoader,它提供了将您的广告很好地集成到内容媒体源中的方法。这样播放器就会知道广告播放并确保不能跳过广告、显示标记等。
AdsMediaSource 用于实现 ExoPlayer 的 IMA extension,但您可以利用这些作为您的解决方案。
回答您关于广告标记的具体问题:
PlayerControlView
有一个方法可以让您设置广告标记位置和布尔值以指示广告是否已显示:
playerControlView.setExtraAdGroupMarkers(
new long[]{10 * 1000, 120 * 1000},
new boolean[]{false, false});
但是,如果您使用的是 PlayerView out-of-the-box,则访问播放器视图以编程方式插入的 PlaybackControlView 会有点困难。因此,您不能使用 findById,而且恐怕 PlayerView 没有为控制器提供 getter。
因此,如果您正在使用 PlayerView,我看到的唯一方法是提供您自己的布局文件 exo_player_view.xml,您可以在其中设置自定义控制器:
在你的项目中创建一个文件res/layout/exo_player_view.xml并将layout file from here复制到其中。
在此布局文件中搜索 ID 为 exo_controller_placeholder 的视图元素。用这个元素替换它:
<com.google.android.exoplayer2.ui.PlayerControlView android:id="@id/exo_controller"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
在onCreate中查找player control view:
playerControlView = findViewById(R.id.exo_controller);
每当你想更新你调用的标记时:
playerControlView.setExtraAdGroupMarkers( new long[]{10 * 1000, 120 * 1000}, new boolean[]{true, false});
第二个参数可让您将广告标记为所示。