8

What am I trying to do:

Using google exoPlayer to play music, foreground and background.

Break into details:

  1. The app launches, google exoPlayer playback control UI should be visible and starts to play immediately.
  2. As soon as the player starts to play, we should see the notification (Using exoplayer's PlayerNotificationManager )
  3. User exits the app either by pressing the back button or swipe from the recent task, the player service should keep running in foreground with notification.
  4. User taps the notification, it should bring up the app.

What I have done: I followed google IO18 on this link https://www.youtube.com/watch?v=svdq1BWl4r8&t=1990s

While I am following the above youtube link, especially the audio app part, I realize one thing, how do you pros add player control UI into this app?

e.g, the app is onDestory, user quits. Then user taps on the notification, back to the MainActivity, there is nothing there, it's an empty screen, question is, how do you add play control ui in here?

I have looked into https://github.com/googlesamples/android-UniversalMusicPlayer tyring to figure out this. However, the Universal Android Music Player Sample is using a giant notification (Not PlayerNotificationManager see on IO18) and custom player UI (Not ExoPlayer out of box control UI) which is confusing me a lot.

Please, please, please help. How to add player control ui in the following code. https://github.com/bizkitj/MediaSessionExoPlayer/tree/ExoPlayerGoogleIO2018

If you can , please not only show me how you do it, I also need to know why did you do it? Break into steps.

Version of ExoPlayer being used:

implementation 'com.google.android.exoplayer:exoplayer-core:2.8.0' 
implementation 'com.google.android.exoplayer:exoplayer-ui:2.8.0'
implementation 'com.google.android.exoplayer:extension-mediasession:2.8.0'

Please be noted, I am tyring to build things upon the googleIO18 demo app. This demo app is using exoPlayer's PlayerNotificationManager which is great to keep sync with MediaSession, I do not want to change this PlayerNotificationManager to android Notification.MediaStyle.

Thank you.

Kurdev
  • 49
  • 8
Bizkit
  • 95
  • 1
  • 5

1 Answers1

0

Since your question is rather about some best practice of managing UI, I try to explain with some general idea:

1- You need a background service which plays the audio and returns START_NOT_STICKY
2- It starts forground as soon as your PlayerNotificationManager listener calls back with some notificationId and notification
3- in your Activity, you bind to the background service which plays the music. this would be better to happen in onStart
4- unbind from the service on onStop

in this way you will have access to the ExoPlayer instance which is working in the background service, you will be able to attach listeners, views, etc. to it as per requirement. Then you will be able to check if there is anything playing to bring up the proper UI
I wish this is helpful for you. Good luck

Masoud Dadashi
  • 1,044
  • 10
  • 11
  • Thank you for the answer and sorry for my very very late response. However, I am looking for a rather detailed step since I am still on the learning path. With your answer, I have to maybe spend hours of searching to 'convert' them into practical code. – Bizkit Sep 25 '18 at 07:29