PlayerNotificationManager - Improve APIs for setting player notification priority
- Dominant language
- Java
- Stars
- 21.9k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
**Note: Works fine on lower API < 29**
On android 10 api 29
I tried the exoplayer example form codelabs and implemented player notifications.
The notification icon in status bar is not shown, but displays in notification drawer as **other** categories with low importance.
Tried setting it to priority high still doesn't show up in Top status bar.
Here's the example code from google.
**playerNotificationManager.setPriority(NotificationCompat.PRIORITY_MAX**);
```
**player.setPlayWhenReady(playWhenReady);
player.seekTo(currentWindow, playbackPosition);
player.addListener(playbackStateListener);
player.prepare(mediaSource, false, false);
..............................
**playerNotificationManager.setPlayer(player);
playerNotificationManager.setColorized(true);
playerNotificationManager.setPriority(NotificationCompat.PRIORITY_MAX);
playerNotificationManager.setColor(getResources().getColor(R.color.colorAccent));**
//mediaSessionConnector.setPlayer(player, null, customAction1.class);
}
.....................
private void releasePlayer() {
if (player != null) {
playbackPosition = player.getCurrentPosition();
currentWindow = player.getCurrentWindowIndex();
playWhenReady = player.getPlayWhenReady();
player.removeListener(playbackStateListener);
player.release();
player = null;
}
}
private MediaSource buildMediaSource(Uri uri) {
DataSource.Factory dataSourceFactory =
new DefaultDataSourceFactory(this, "exoplayer-codelab");
DashMediaSource.Factory mediaSourceFactory = new DashMediaSource.Factory(dataSourceFactory);
MediaSource mediaSource1 = mediaSourceFactory.createMediaSource(uri);
// Additionally, create a media source using an MP3.
MediaSource mediaSource2 = mediaSourceFactory.createMediaSource(uri);
return new ConcatenatingMediaSource(mediaSource1, mediaSource2);
}
@SuppressLint("InlinedApi")
private void hideSystemUi() {
playerView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
}
private class PlaybackStateListener implements Player.EventListener{
@Override
public void onPlayerStateChanged(boolean playWhenReady,
int playbackState) {
String stateString;
switch (playbackState) {
case ExoPlayer.STATE_IDLE:
stateString = "ExoPlayer.STATE_IDLE -";
break;
case ExoPlayer.STATE_BUFFERING:
stateString = "ExoPlayer.STATE_BUFFERING -";
break;
case ExoPlayer.STATE_READY:
stateString = "ExoPlayer.STATE_READY -";
break;
case ExoPlayer.STATE_ENDED:
stateString = "ExoPlayer.STATE_ENDED -";
break;
default:
stateString = "UNKNOWN_STATE -";
break;
}
Log.d(TAG, "changed state to " + stateString
+ " playWhenReady: " + playWhenReady);
}
}
}**
```
Contributor guide
Assessment
This issue has not been assessed yet.