Exoplayer: Allow setting of VIDEO_SCALING_MODE when using SimpleExoPlayer

Created on 29 Oct 2016  路  9Comments  路  Source: google/ExoPlayer

I need a center crop function for my player, thus I cant use SimpleExoPlayer (at least I didnt find how to do that with SimpleExoPlayer). I found that I can set center crop parameter when creating video renderer, which I can pass to the instance of ExoPlayer:

final ExoPlayer player = ExoPlayerFactory.newInstance( new Renderer[]{videoRenderer, audioRenderer}, trackSelector, loadControl);

But ExoPlayerdoesnt have method setVideoSurfaceView().
How do I pass a SurfaceView to a non-simple ExoPlayer?

enhancement

Most helpful comment

We're going to add a setVideoScalingMode method to SimpleExoPlayer (and also C.MSG_SET_SCALING_MODE that you can send directly to the renderer, if not using SimpleExoPlayer). We don't have any plans to change the default.

All 9 comments

SimpleExoPlayer is itself just a wrapper around a regular ExoPlayer, so the easiest way to answer this kind of question is to take a look at what SimpleExoPlayer does here :). You're probably building what is effectively a wrapper of your own, so it might even make sense for you to use SimpleExoPlayer as a starting point for your own wrapper, and simplify and modify it to suit your exact use case.

We should possibly consider adding support for this to SimpleExoPlayer directly. It's a little awkward because that configuration parameter is specific to SurfaceView, but we could probably find a way that's not too confusing. Is that the only reason you can't use SimpleExoPlayer, or are there additional reasons on top of that?

@wilkenas Just be curious, how did you do this

I can set center crop parameter when creating video renderer

Thank you @ojw28 for the pointer, I managed to make my code work. Though I'm still a noob and dont understand some things. For example, why I'm not getting method setVideoSurfaceView(), though it is defined as public in given code. The reason why I cant use SimpleExoPlayer or MediaPlayer, because for my educational app I need seamless video loop with no video controls played as fullscreen background and maintaining aspect ratio on all devices.

@eneim I did that by copying this line of code from one of the examples found:

MediaCodecVideoRenderer videoRenderer = new MediaCodecVideoRenderer(this, MediaCodecSelector.DEFAULT, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);

I'm unsure what you mean by:

For example, why I'm not getting method setVideoSurfaceView(), though it is defined as public in given code.

setVideoSurfaceView is only available on SimpleExoPlayer and not on ExoPlayer, so it's expected that you wont see it if you're using non-simple ExoPlayer.

It does sound like we should provide a way for you to set the scaling mode and still use SimpleExoPlayer, for convenience. We'll use this issue to track this.

Sorry, I got confused simple and non-simple instances! Anyway, I'm happy with the solution found.

I really think this should have a high priority. The inability to choose a scaling mode makes this simple implementation (almost) useless IMHO, and people will have to use the regular ("less simple") ExoPlayer almost all the time :).

To keep things in perspective, it's only "almost useless" if you're one of the minority of developers who actually wants to specify the other scaling mode. You can also take what's there and modify one line of code, so there's still clearly added value in the other ~850 lines of code in that class compared with you having to write everything from scratch. Or to put it another way, "almost useless for you" != "almost useless" ;).

We will look at this quite soon, however.

Thanks for your reply! I agree it can be used in some cases, and also as sample code :)
Maybe a "quick win" could be to use VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING by default? I mean, not deforming the video would make more sense as a default in my opinion.

We're going to add a setVideoScalingMode method to SimpleExoPlayer (and also C.MSG_SET_SCALING_MODE that you can send directly to the renderer, if not using SimpleExoPlayer). We don't have any plans to change the default.

Was this page helpful?
0 / 5 - 0 ratings