简而言之:我们在 android 上使用 reacte native,并使用原生 VideoView 使用适用于 android 的 Google IMA SDK 显示带有广告的视频。视频播放,广告播放,但包含“阅读更多”和“跳过广告”的 Web 视图不可见。它被添加到视图层次结构中,但它的大小为 0,0 并且没有子级。当我在本机应用程序中使用完全相同的代码时。一切都按预期工作。
更多上下文:
- 视频播放器/google ima sdk 集成直接从 google ima 示例应用程序复制而来。
- 当组件放置在本机 anroid 应用程序中时,一切正常。
- 检查视图层次结构时,很明显添加了 webview,它的大小为 0,0
- 当我自己添加一个本机 webview 时,它的表现非常好。
React Native 组件的相关代码:
@SuppressLint("ViewConstructor")
public class ReactVideoViewWithAds extends FrameLayout implements
LifecycleEventListener {
private VideoPlayerWithAdPlayback mVideoPlayerWithAdPlayback;
private RelativeLayout mCompanionAdSlot;
private VideoPlayerController mVideoPlayerController;
public ReactVideoViewWithAds(ThemedReactContext themedReactContext) {
super(themedReactContext);
createViews();
themedReactContext.addLifecycleEventListener(this);
}
private void createViews() {
FrameLayout.LayoutParams companionAdLayoutParams = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
(int) (50 * getResources().getSystem().getDisplayMetrics().density));
companionAdLayoutParams.gravity = Gravity.CENTER_HORIZONTAL;
mCompanionAdSlot = new RelativeLayout(getContext());
mCompanionAdSlot.setBackgroundColor(Color.BLUE);
addView(mCompanionAdSlot, companionAdLayoutParams);
//player with ad playback
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT);
mVideoPlayerWithAdPlayback = new VideoPlayerWithAdPlayback(getContext());
addView(mVideoPlayerWithAdPlayback, layoutParams);
initPlayer();
}
private void initPlayer() {
mVideoPlayerController = new VideoPlayerController(
getContext(),
mVideoPlayerWithAdPlayback,
null,
null,
"nl",
mCompanionAdSlot,
null);
}