4

I am trying to use exoplayer in my app, and i am following MVVM design pattern, i want to make PlayerViewModel class where it handle all the actions of player (play tracks,pause,next,... so on), but i faced a problem that i need to initialize the SimpleExoPlayer with context but ViewModel could not have context

SimpleExoPlayer exoPlayer = ExoPlayerFactory.newSimpleInstance(getApplicationContext(), trackSelector); 

any suggestion what i should do ?
Thanks in advance

Muhamed Raafat
  • 257
  • 5
  • 14

1 Answers1

1

Use AndroidViewModel. It contains the application context. It is in the Android Architecture Components library.

user221256
  • 415
  • 5
  • 14