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);
Related
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!
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
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.
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
I want to realise an Android application that shows an always in foreground popup (even in front of the call screen) similiar to the one visible when you use the volume control keys. Sadly, neither toasts nor notifications are sufficient for my needs.
I experimented a lot with #android:style/Theme.Dialog, but the dialogs it creates are mostly not in the foreground.
How do I create what I need or how is the always-foreground popup implemented in Android?