Android MediaSession: How to choose the icons shown on lock screen? - android

I have an app that plays media via MediaSessionCompat.
I create a notification for the Notification Drawer using NotificationCompat and post it using NotificationManagerCompat.notify, and it looks great. (See screenshot.)
My problem is with the lock screen. It only shows Play, Previous Track, and Next Track icons. I'm missing the controls to jump back and forward within the currently playing track. (See screenshot.)
I'm using MediaSession.setPlaybackState to specify the actions that are available, and I am including all the appropriate ones from PlaybackStateCompat for rewind, fast forward, skip to previous, and skip to next.
Is the lock screen configured differently than the notification? Or do developers simply have less control over the controls provided here?
Thank you in advance!

Related

Android TV - resume already started content from home

I am new to Android TV programming and just managed to have an App that starts a video from an ExoPlayer implementation.
When I hit the HOME-button the home is shown and the content I started appears in the purple marked area. I can resume my App from here.
TV Emulator - Android 10
Can you tell me how this area is called?
How can I control which meta data is shown?
I only found information about the Watch Next Card, but it seems to be something different.
That seems to be the notification area. It's not exclusive to playback.
For example, notifications for a firmware update will also appear there.
To have a proper now playing car and display metadata and other info see this:
https://developer.android.com/training/tv/playback/now-playing.html

API to draw menu over leanback launcher?

I'd like to create an app (actually just a menu) that should work just like the Android TV settings menu.
To be more specific, I'd like my app to cover only part of the screen and let any background video play on the remaining area (exactly like what happens with the settings menu).
Here's a picture of what I'd like to obtain:
This means that I should be able to:
open Live Channels
play some content
press the home button (at this point the channel will be playing in background behind the leanback launcher)
open my app, and have the background content continue playing
Of this, I just need to figure out how to obtain point 4, the rest is just how Android TV works by default.
Just to be clear, I don't want advices on how to create an app that plays a video and has a side menu, I want to integrate this menu inside the existing Android TV background videos feature.
Is it possible? I can't find any API for this.
For the app, you can do that using a transparent theme on the activity, that should keep the background visible (you can also decide to have a pseudo-transparent background to partially hide what's behind the activity, same way settings do).
The other question about playing the live channel on the background of the leanback launcher, I am not sure, but it sounds like it should be the standard procedure.

Volume slider while casting

I need to show the volume slider while casting an audio content to a Chromecast remote.
If I put the app to the background the slider is shown (see this).
The problem is that the framework does not show the slider when the app is not in the background.I guess it is because an application can decide to do something else.
I have tried to call
mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_SAME, AudioManager.FLAG_SHOW_UI);
with no success: the slider that is shown does not have the Chromecast icon and does not report the current volume on the remote. In other words the slider is related with the local audio volume.
is there a way to ask the framework to keep showing the slider even when the app is in the foreground?
Edited
Actually the behaviour even with the VideoCast app is a bit inconsistent. On some phones it is enough to bring the app in the background and make the framework showing the volume slider. After that it will keep showing it even when the app is in the foreground. On other phones this does not work or it is not necessary because the slider is shown correctly.
There is a bit of improvement that can be made; when media is playing back (i.e. if it is not on pause), you can achieve what you want. To see how, you need to override onKeyDown; take a look at the CastVideos-android sample, in class VideoBrowserActivity and try that to see if it does what you'd like or not.
Since you want to show the Chromecast control instead of the generic music control, you need to call:
mAudioManager.adjustSuggestedStreamVolume(AudioManager.ADJUST_SAME,
AudioManager.USE_DEFAULT_STREAM_TYPE, AudioManager.FLAG_SHOW_UI);

Android 4.x RemoteControlClient.setTransportControlFlags() not working?

I'm trying to use the RemoteControlClient class to support the lock screen player with my app. One issue is that setting the transport control flags seems like they don't work properly.
For example I'm trying to just show a play/stop icon no prev/next:
mRemoteControlClient.setTransportControlFlags(
RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE |
RemoteControlClient.FLAG_KEY_MEDIA_STOP);
This shows a previous icon and pause icon! Why?
To make things even worse when pressing the stop/play button you only receive KEYCODE_MEDIA_PLAY_PAUSE when you should be getting KEYCODE_MEDIA_STOP or KEYCODE_MEDIA_PLAY.
This is frustrating poor development on Android side if I find out I'm doing this correctly.
The FLAG_KEY_MEDIA_STOP never shows stop because of bug in android as reported here:
https://code.google.com/p/android/issues/detail?id=29920
If you use the flag PLAY_PAUSE is should not produce a KEYCODE_MEDIA_STOP event. Why would it?
It is a play/pause toggle action that does what it is intended to. It is up to your application to store the state of your media player.
If I understand the documentation correctly you could get KEYCODE_MEDIA_PLAY or KEYCODE_MEDIA_PAUSE only if you use the flags FLAG_KEY_MEDIA_PLAY and FLAG_KEY_MEDIA_PAUSE.
But android might be "clever" and translate it to a toggle.
I'm not sure about that.
Use the FLAG_KEY_MEDIA_PLAY_PAUSE
oRemoteControlClient.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE);
And lie to the RemoteControlClient ;-)
Tell him the stream is buffering and it will show the stop button!
oRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_BUFFERING);
Cheers

Is there a list of "best practices" for Android games?

I'm writing my first Android game, and though the game itself is working well, I'm not too sure about some of the Android integration aspects of it. Specifically:
Should I provide an in-game volume control?
Should I hide the status bar?
Is the Menu button generally used to pause the game, or should I provide an on-screen control for this?
etc.
Basically I just want my game to do everything the "standard" way. I don't want to frustrate users. Is there some resource (official or not) that lists recommendations for such things? Alternatively, can anyone give me a few important guidelines?
There are no official guidelines how to do this, but some 'Android common sense' would be advisable.
As usual, there is more than one way to do anything, but most of the apps seem to follow the following principles:
full screen games (especially ones in landscape mode) seem to hide the status bar most of the time
you should override the menu button, so it does not get pressed accidentally, but provide a quick way to leave the game
back button usually pauses the app
you do not need in-game volume control since all of existing android devices include a volume rocker, but make turning the volume off available as soon as the game (splash screen) starts, preferably give the person a few moments to turn it off before the music start (a 'would you like to turn the music down?' dialog would be nice)
an (as usually on android) don't count on anything and specify special game requirements (trackpad support, min screen size, ...) in the manifest file
hopefully you can find some more resources online

Categories

Resources