Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android and HDMI CEC

Tags:

I am using a PlugPC (compute stick) with Android version 4.4.4, connecting it to HDMI port of TV to control what is being displayed on the TV. My app starts on boot, taking control of the screen. Now through my app I want to control TV volume and source switch (maybe). I have following questions in this regard:

  1. Is there a way to send HDMI-CEC commands via android using Java to control TV volume, switch on/off, etc on those TVs compatible ?

  2. Any Java library provided by android or otherwise available for the same ?

  3. A simple Java example using CEC.

P.S - I understand the theory presented in the (https://source.android.com/devices/tv/HDMI-CEC.html), but clueless on how to implement with code. Please be specific with your answers to above questions.

like image 581
jay Avatar asked Sep 09 '16 21:09

jay


People also ask

What is CEC control in Android TV?

CEC (Consumer Electronics Control) allows for HDMI devices to be controlled with one remote control. If you try to cast to a CEC supported TV while on a different source input (local TV channel, Cable, USB), source input will automatically switch to the HDMI port where the Chromecast is connected.

How do I connect my Android to my TV via HDMI?

Connect the wireless display adapter into your TV's open HDMI port and into a power outlet. Change the input source on your TV to the appropriate HDMI input. In the settings menu of your Android, open the “wireless display” application. Select your adapter from the list of available devices.

How do I enable HDMI-CEC?

Just press the Menu button on your TV remote and open “Setup”. Next, navigate to “HDMI Control” and then open “CEC”. Finally, turn on the toggle. There you have it!


1 Answers

Yes it is entirely possible to do, however it is incredibly fickle. HDMI CEC works like a bus. Usually, in both directions.

Your questions:

  1. Yes. Though I use JNI to access native code that does the actual work. You might be able to do it purely in Java.
  2. Probably not. The issue is that each vendor implements the code to send CEC signals. There is no common functionality at all, except for the CEC commands themselves. The device file accessed is likely unique in most devices, especially from vendor to vendor. Therefore, any libraries that are created most support a wide range of different vendors and their quirks, and it would not be future proofed against the next vendor changes.
  3. Unfortunately I cannot provide my working code. I provide a link below to an Amlogic source file on github that does a lot of the work. My code looks similar.

Some of my own points:

  1. Not all devices support all commands. Many less used commands will not be implemented, because it costs more.
  2. Interacting with CEC is often vendor dependant. They will likely have their own library or device file to work with.
  3. CEC will not always work in both directions, it depends whether the vendor implemented that functionality. It is not always implemented, because it costs more to do.

To do it properly you will likely need to implement your code using JNI to form the proper packets. You might find this useful, at least for Amlogic.

The device access point that I use in my devices is /dev/amhdmitx0. You can send your well formed packets to that location.

Here is a useful website that can tell you how how to form a CEC command: http://www.cec-o-matic.com/.

Unfortunately, I cannot share much more than this of what I have written. For various legal reasons.

The best thing that you can do is to seek help from the vendor you are programming for. If you are coding for a specific platform. They might be willing to help you.

like image 123
Knossos Avatar answered Oct 05 '22 12:10

Knossos