You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I have a list of video items,
Im trying to use the same instance of exoplayer in recycler view when scrolling between items.
when i'm using normal HlsMediaSource the player works perfectly and very fast,
when I wrap the HlsMediaSource with ImaAdsMediaSource, the first video plays normally, but when i scroll to the next item i get an IndexOutOfBoundsException in TimeLine.getPeriod (in TimeLine.EMPTY instance) (adding stacktrace below)
java.lang.IndexOutOfBoundsException
at com.google.android.exoplayer2.Timeline$1.getPeriod(Timeline.java:532)
at com.google.android.exoplayer2.Timeline.getPeriod(Timeline.java:687)
at com.google.android.exoplayer2.ExoPlayerImpl.getContentPosition(ExoPlayerImpl.java:375)
at com.google.android.exoplayer2.SimpleExoPlayer.getContentPosition(SimpleExoPlayer.java:794)
at com.google.android.exoplayer2.ui.PlaybackControlView.updateProgress(PlaybackControlView.java:797)
at com.google.android.exoplayer2.ui.PlaybackControlView.updateAll(PlaybackControlView.java:647)
at com.google.android.exoplayer2.ui.PlaybackControlView.show(PlaybackControlView.java:602)
at com.google.android.exoplayer2.ui.SimpleExoPlayerView.showController(SimpleExoPlayerView.java:769)
at com.google.android.exoplayer2.ui.SimpleExoPlayerView.maybeShowController(SimpleExoPlayerView.java:750)
at com.google.android.exoplayer2.ui.SimpleExoPlayerView.access$500(SimpleExoPlayerView.java:199)
at com.google.android.exoplayer2.ui.SimpleExoPlayerView$ComponentListener.onPlayerStateChanged(SimpleExoPlayerView.java:907)
at com.google.android.exoplayer2.ExoPlayerImpl.handleEvent(ExoPlayerImpl.java:422)
at com.google.android.exoplayer2.ExoPlayerImpl$1.handleMessage(ExoPlayerImpl.java:103)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
this is my code (relevant to the issue):
public class SingleVideoPlayer {
private SimpleExoPlayer exoPlayer;
private Context context;
private ImaAdsLoader imaAdsLoader;
public SingleVideoPlayer(Context context, String adTagUrl) {
this.context = context;
imaAdsLoader = new ImaAdsLoader(context, Uri.parse(adTagUrl));
DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
DefaultTrackSelector trackSelector = new DefaultTrackSelector(bandwidthMeter);
exoPlayer = ExoPlayerFactory.newSimpleInstance(this.context, trackSelector);
}
public void playVideoItem(final VideoListItem videoListItem, final VideoViewHolder viewHolder, int newActiveViewPosition) {
setNewSource(videoListItem.getVideoUrl(), viewHolder.getSimpleExoPlayerView());
viewHolder.getSimpleExoPlayerView().setPlayer(exoPlayer);
}
public void setNewSource(String videoUrl, FrameLayout adUiContainer) {
Uri uri = Uri.parse(videoUrl);
String userAgent = Util.getUserAgent(context, "appName");
DefaultHttpDataSourceFactory defaultDataSourceFactory = new DefaultHttpDataSourceFactory(userAgent);
MediaSource mediaSource = new HlsMediaSource(uri, defaultDataSourceFactory, null, null);
ImaAdsMediaSource imaAdsMediaSource =
new ImaAdsMediaSource(mediaSource, defaultDataSourceFactory, imaAdsLoader, adUiContainer);
exoPlayer.prepare(imaAdsMediaSource);
exoPlayer.setPlayWhenReady(true);
}
public void stopPlayback(VideoViewHolder viewHolder, int oldActivePosition) {
exoPlayer.stop();
}
}
I managed to solve this by creating a new instance of ExoPlayer every time i start a new video, but i really don't want to do this.
any help would be appreciated :) thanks!
edit:
the exception only occurs when scrolling while there is an ad currently playing and you scroll to another item
The text was updated successfully, but these errors were encountered:
can you show us your code,how can we use exoplayer inside recyclerview (Chat type screen) where we can play any video in multiple list of videos(Like whatsapp)
Hi,
I have a list of video items,
Im trying to use the same instance of exoplayer in recycler view when scrolling between items.
when i'm using normal
HlsMediaSource
the player works perfectly and very fast,when I wrap the
HlsMediaSource
withImaAdsMediaSource
, the first video plays normally, but when i scroll to the next item i get an IndexOutOfBoundsException inTimeLine.getPeriod
(inTimeLine.EMPTY
instance) (adding stacktrace below)this is my code (relevant to the issue):
I managed to solve this by creating a new instance of ExoPlayer every time i start a new video, but i really don't want to do this.
any help would be appreciated :) thanks!
edit:
the exception only occurs when scrolling while there is an ad currently playing and you scroll to another item
The text was updated successfully, but these errors were encountered: