2

Components common to all ExoPlayer implementations are:

  • A MediaSource that defines the media to be played, loads the media, and from which the loaded media can be read. A MediaSource is injected via ExoPlayer.prepare at the start of playback.
  • Renderers that render individual components of the media. Renderers are injected when the player is created.
  • A TrackSelector that selects tracks provided by the MediaSource to be consumed by each of the available Renderers. A TrackSelector is injected when the player is created.
  • A LoadControl that controls when the MediaSource buffers more media, and how much media is buffered. A LoadControl is injected when the player is created.

As I understand from this context, it looks like injection is something like initialization rather than instantiation. Is that right?

2 Answers 2

6

That is correct. Instead of making ExoPlayer implementation instantiate every single Renderer there is, you instantiate only those that you actually need for that particular implementation, and then inject them into the implementation, thus decoupling the ExoPlayer class from Renderer class.

See Dependency Injection for more details.

5

Injecting any value comes from the concept of dependency injection. At it's core, dependency injection defers to run time the actual implementation of an interface it is going to use for your application.

Here are a few characteristics:

  • You code to interfaces. This allows easy mocking or stubbing for unit tests and using the real code in production
  • Something outside your class provides the implementation. (i.e. injecting the component)
  • The promise is that your code becomes more modular and more flexible.

That said, dependency injection is not limited to injecting components. It can also inject configuration values.

The term inject basically means provide the implementation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.