Make SimpleExoPlayerView non-final?
I'm on r2.2.0, is there any special reason to make this View final? If not, can you make it non-final so when one (like me, for example) wants to have some customize on it, he/she doesn't need to add one more View layer to include it in.
Here is what I'm trying to do to wrap the MediaSource/SimpleExoPlayer creation logic into a ViewGroup to help my users' life easier: link . Making the view non-final will help a lot in term of View inflation performance.
Thanks.
I, too, had to clone to class just to add extra functionality to it. Being able to extend it would be great.
Making the view non-final will help a lot in term of View inflation performance.
Will it really? Can you provide some data that backs up this claim? Allowing extension looks like it would let you to remove one FrameLayout from the view hierarchy, but I doubt this has much of a measurable performance impact. It might also be possible for your users to eliminate the additional view by including yours using the
Is there any special reason to make this View final?
We make things final where we don't think there's a good argument for extension as a way of limiting the (already very large) API surface, and guiding developers toward other (preferred) way of achieving their goals. @botondbutuza - What's your use case for requiring extension?
I had to add an extra button (go live), and extra listeners on the view level, for our internal logging procedures. If there's a better way than making a copy of the class, I'm all ears - obviously we can edit the xml, but manipulating the controls programmatically is still impossible from what I can see.
Adding an extra button could be pretty easily done without extension. Replacing the layout using one of the approaches described here would let you add an additional button, and you could find that button in a wrapping class using findViewById as normal.
I'm less sure about logging. It looks like almost everything in SimpleExoPlayerView is private, so I doubt you're able to access anything extra via extension. Or have you also modified SimpleExoPlayerView to make a whole bunch of private stuff protected instead? I don't think we can/will commit to not making breaking changes to what are effectively internal implementation details. So whilst this approach might work, you'll end up with your extension class repeatedly breaking when you update to a newer version of the library. In which case aren't you better off just taking a copy of the class and adapting it cleanly to suit your needs?
Regarding the extra button - I could do that, but separation of concerns would then be violated. My view would have to deal with some player control logic, instead of the view that was specifically made to encapsulate all of that logic, which seems backwards.
Yeah. I'm not really convinced extension is really the right way to do it though. If the base class doesn't know about the views you're adding, it's not necessarily going to just "do the right thing" (e.g. show and hide the button at the correct times). It might work right now for your use case, but I suspect there are lots of other use cases where it wont work quite right. The logging part is also not really addressed. Isn't it better just to fork the class?
@ojw28 I see the class has been made extendable since this issue arose.
I now need to do some extra operations while the user is seeking - I wonder how you'd go about doing this? I basically need access to the onProgressChanged method, and I don't really want to copy the whole componentListener over, and implementing its dependencies.
I ended up implementing the necessary functions of componentListener, copying over the contents of onStartTrackingTouch, onProgressChanged, and onStopTrackingTouch. It pretty much does what I need it, and maintaining it won't be as much of a nightmare.
Now, however, when the user is scrubbing, the thumbnail jumps around: this is because componentListener's dragging boolean is used in updateProgress, neither of which I can change, of course. So, back to the drawing board.
If you want to customize controls to this extent, you're really best off just forking the class and adapting it to suit your needs.