我有以下代码(可在我的应用程序的不同部分上运行,但在recyclerview中不能很好地工作)。
如标题中所述-我听到了视频或广告的声音(甚至是控制器和广告按钮),但听不到视频本身(视频链接很好,请在同一位置的同一播放器上检查该声音)该应用程序。
if (loadControl == null) {
loadControl = new DefaultLoadControl.Builder().
setAllocator(new DefaultAllocator(true, 16)).
setBufferDurationsMs(VideoPlayerConfig.MIN_BUFFER_DURATION,
VideoPlayerConfig.MAX_BUFFER_DURATION,
VideoPlayerConfig.MIN_PLAYBACK_START_BUFFER,
VideoPlayerConfig.MIN_PLAYBACK_RESUME_BUFFER).
setTargetBufferBytes(50).
setPrioritizeTimeOverSizeThresholds(true).
createDefaultLoadControl();
}
GameCenterHandsetDetailsFragment.player = ExoPlayerFactory.newSimpleInstance(/*App.getInstance(),*/
new DefaultRenderersFactory(App.getInstance()),
new DefaultTrackSelector(),
loadControl);
GameCenterHandsetDetailsFragment.player.prepare(
buildMediaSource(
MonetizationMgr.getSettings().getTermInSettingsMoreSettings("STICKY_VIDEO_NEWS_SOURCE"),
imaTag, myHolder));
GameCenterHandsetDetailsFragment.player.addAnalyticsListener(new EventLogger(/* trackSelector= */ null));
GameCenterHandsetDetailsFragment.player.addListener(this);
myHolder.playerView.setPlayer(GameCenterHandsetDetailsFragment.player);
myHolder.playerView.setVisibility(View.VISIBLE);
myHolder.playerView.setControllerHideDuringAds(false);
myHolder.playerView.setUseController(false); private MediaSource buildMediaSource(String videoUrl, String tag, ViewHolder myHolder) {
MediaSource RetVal = null;
try {
DefaultDataSourceFactory dataSourceFactory =
new DefaultDataSourceFactory(App.getInstance(),
Util.getUserAgent(App.getInstance(),
App.getInstance().getString(R.string.app_name)));
MediaSource mediaSource = new ExtractorMediaSource.Factory(dataSourceFactory).setExtractorsFactory
(new DefaultExtractorsFactory()).createMediaSource(Uri.parse(videoUrl));
if (tag != null) {
RetVal = new AdsMediaSource(mediaSource, dataSourceFactory, getImaAdsLoader(tag, myHolder.playerView),
myHolder.playerView.getOverlayFrameLayout());
}
NewsCenterActivity.sendRequestAdVideos("LMT", "1");
} catch (Exception e) {
e.printStackTrace();
}
return RetVal;
}
private AdsLoader getImaAdsLoader(String tag, PlayerView playerView) {
ImaAdsLoader adsLoader = null;
try {
Uri uri = Uri.parse(tag);
ImaSdkSettings imaSdkSettings = ImaSdkFactory.getInstance().createImaSdkSettings();
/** autoplay **/
if (MonetizationMgr.getSettings().getTermInSettingsMoreSettings("") != null &&
Boolean.valueOf(MonetizationMgr.getSettings().getTermInSettingsMoreSettings("")))
{
imaSdkSettings.setAutoPlayAdBreaks(true);
} else {
imaSdkSettings.setAutoPlayAdBreaks(false);
}
imaSdkSettings.setDebugMode(true);
ImaAdsLoader.Builder adsBuilder = new ImaAdsLoader.Builder(App.getInstance());
adsBuilder.setImaSdkSettings(imaSdkSettings)
.setVastLoadTimeoutMs(30 * 1000);
adsBuilder.setAdEventListener(new LmtEventListener(this, playerView));
adsLoader = adsBuilder.buildForAdTag(uri);
} catch (Exception e) {
e.printStackTrace();
}
return adsLoader;
}
我也从Logcat得到以下信息:
2019-11-12 21:06:12.374 15360-15401 /? E /铬: [ERROR:tile_manager.cc(779)]警告:已超出图块内存限制, 某些内容可能无法绘制
我在gradle中使用以下版本:
//ExoPlayer
implementation 'com.google.android.exoplayer:extension-ima:r2.8.4'
implementation 'com.google.android.exoplayer:exoplayer:2.8.4'