-1

I am trying to create a TikTok like app, for that I am using viewPager2, FragmentStateAdapter and ExoPlayer(2.16.1),

I am injecting new instance of exoPlayer in every new VideoFragment and initializing/prepare exoplayer in onViewCreated method and starts it on onResume and releasing it on onDestroy

The issue is in some devices app can not prepare more than 1 exoplayer instance otherwise it's throwing following error, I understand the issue and why its happening but,I need some solution achieve my requirement which preloading next video like TikTok

com.google.android.exoplayer2.ExoPlaybackException: MediaCodecVideoRenderer error, index=0, format=Format(2, null, null, video/avc, avc1.4D4832, 3988960, null, [1280, 2276, -1.0], [-1, -1]), format_supported=YES

Nick ODell
  • 15,465
  • 3
  • 32
  • 66
Ankit Pandey
  • 220
  • 5
  • 9
  • Are you setting `playWhenReady = true` for both the instances and calling prepare on them? – Kalpesh Chandora Jan 19 '22 at 11:34
  • No, I am setting playWhenReady =true for only one instance at a time, but i am preparing three instance of exoplayer at a time – Ankit Pandey Jan 20 '22 at 13:56
  • That truncated stacktrace makes the question kind of theoretical, that's almost as bad as no stacktrace at all... and there is no code either. `ViewPager2` constructs & destructs views with some pages lookahead. – Martin Zeitler Jan 20 '22 at 18:41

1 Answers1

0

Generally speaking, you may want to add some method onLateInit() to overcome that lookahead Fragment construction from ViewPager2, by being able to manually trigger it's initialization at the desired point in time. Since you skipped all code and most of the stacktrace, you'll have to figure this out by yourself - but I'm almost certain, that this depends upon the fact, that you may initialize ExoPlayer onCreate() or onViewCreated() ...just add some logging and you'll see that these events happen at completely different points in time, than you might assume. Just try this out ...

Martin Zeitler
  • 1
  • 19
  • 155
  • 216