tcking / GiraffePlayer2

out of the box android video player(support lazy load, ListView/RecyclerView and hight performance)
Apache License 2.0
377 stars 110 forks source link

CustomizedMediaController not effictive for first run #145

Closed TechyM closed 5 years ago

TechyM commented 5 years ago
PlayerManager playerManager=PlayerManager.getInstance();

    playerManager.setMediaControllerGenerator(new PlayerManager.MediaControllerGenerator() {
        @Override
        public MediaController create(Context context, VideoInfo videoInfo) {
            Log.d("MyApp","media controller generator");
            return new SimpleMedialController(context);
        }
    });

    binding.viewVideo.setVideoPath(url);

    Log.d("MyApp","setupvideo");

   binding.viewVideo.getPlayer().start();

here when i first time run my app. "setupvideo" is logged first, when i press back button and then run app again only then this "media controller generator" is logged...

i want to set my customized mediacontroller before starting the video.

tcking commented 5 years ago

the playerManager.setMediaControllerGenerator should be called before view init,for example in onCreate before setContentView

TechyM commented 5 years ago

thank you so much !! that was great help!

TechyM commented 5 years ago

what if I want to change mediacontroller to DefaultMediaController after completion of video.

@Override public void onCompletion(GiraffePlayer giraffePlayer) { super.onCompletion(giraffePlayer); Log.d("MyApp","Video Completed"); Remember.putBoolean(videoCompletedOnce,true); PlayerManager.getInstance().setMediaControllerGenerator(new PlayerManager.MediaControllerGenerator() { @Override public MediaController create(Context context, VideoInfo videoInfo) { Log.d("MyApp","Defaultmedia controller generator"); return new DefaultMediaController(context); } }); }

tcking commented 5 years ago

the media controller is bind in view init.So you can't change it at runtime.In your case the setup video can play in a independent activity and in MediaControllerGenerator create MediaController by video info:

public MediaController create(Context context, VideoInfo videoInfo) {
if("your setupvideo url".equals(videoInfo.getUri())){
    return new SimpleMedialController(context);
}
return new DefaultMediaController(context);
}