media player - Android ExoPlayer becomes Green and Pixelated onResume() -
in android app, have media player implements exoplayer interface.
when home button pressed, player supposed pause. then, when app relaunched recent apps, player should continue playing left off.
originally, called player.release()
in onpause()
, got rid of entire player instance. then, when app resumed, created new instance of player , used seekto()
jump correct position.
@override public void onpause() { if (player != null) { saveplayerposition(); player.release(); player = null; } super.onpause(); } @override public void onresume() { super.onresume(); if (!player.isplaying()) { player = exoplayerfactory.newsimpleinstance(context, trackselector, new defaultloadcontrol(), drmsessionmanager); setplayerlisteners(); exoplayerview.setplayer(player); player.setplaywhenready(false); player.seekto(playerwindow, playerposition); } }
the problem above code every time loaded app recent apps, player took few moments reconnect , load video, instead of retaining buffered data , right away resuming play.
in order solve issue, change code instead toggle setplaywhenready()
.
@override public void onpause() { if (player != null) { player.setplaywhenready(false); } super.onpause(); } @override public void onresume() { super.onresume(); if (player != null && !player.isplaying()) { player.setplaywhenready(true); } }
this fixed reloading issue , video resumes playing right away left off. however, when video resumes, first few seconds, video off color , pixelated, shown in picture below:
after video plays few seconds, resumes normal coloration , smooth appearance. seeing issue when using actual device emulator.
what causing player messed up? how can fix or avoid this?
it seems issue fixed release of exoplayer v2.3.0.
it still not perfect, though. now, instead of turning green , pixelated, audio begins playing fraction before video joins in. jump way less noticeable green screen, however, considering fix.
Comments
Post a Comment