I have just bought a new Chromecast with Google TV and hooked it up to my A/V-Receiver+Beamer setup, but I will refer to it as "TV" further on as it doesn't make a difference here.
According to Android Police - How to control Chromecast with Google TV volume using your phone, there are three options:
- TV volume is controlled via HDMI CEC using the Chromecast remote
- TV volume is controlled via Infrared using the Chromecast remote
- Chromecast volume is controlled via the Chromecast remote
I can't combine those options.
Options 1) and 2) mean I can't use my phone or Google Assistant to change the volume of what I'm playing. Option 3) means I will lose support for 5.1 surround sound, so this is an option I do not want to use in my home cinema setup.
So apparently, I'm out of luck end of the story.
BUT:
In the Google Home app, I can open my Chromecast and open a remote on my phone and it has volume buttons, with which I could control the volume of my TV (as if I would have pressed the buttons on my Chromecast remote), if I chose option 1) above.
So this is proof that it is indeed possible to control the volume directly from my phone AND have support for 5.1 sound. It's just hidden underneath a lot of clicking around.
I'm not new to programming at all, I have worked as a Java developer in the past for almost a decade), but I'm completely new to Android development.
I want to figure out how feasible it is to write an app which essentially does the following:
The app is in the background, no user interface is visible. It hijacks the physical volume controls of the phone (this is doable at least when you're within an app (aCalendar does this and allows you to scroll with those buttons). It determines whether media is currently streamed to a Google Cast device (which seems to be doable as well), determines whether that device being cast to supports volume control (or determines whether the device is a Chromecast with Google TV, and ends up with the same result) and if yes, it sends a volume up/down event to that Chromecast.
If not, the app just forwards the event to Android and it behaves as normal (e.g. by changing the phone's internal volume, changing the in-call volume, etc.).
More specific questions:
- Is it possible to intercept volume-button presses in an app which runs in the background (please excuse me if I'm not using correct Android terminology heere)?
- Is it possible to forward intercepted volume button presses to the OS, so that the default behavior of those buttons doesn't break?
- Is it possible to determine whether media is being streamed to a cast device?
- Is it possible to determine whether that device is supporting volume controlling or alternatively determine what model of Chromecast it is?
- Is it possible to send volume events or remote-key presses to that device, like the Google Home app does?
I know, the question is rather long, but the topic is quite complex on the other hand.