12

I have an android TV (Philips 49PUS6401) I want to connect a surround sound system to it which is much better quality than the built in speakers even when only being used in stereo.

however this TV separates the volume control for the master output and the headphone output, the result being that even with the in TV speakers turned off, the volume keys on the remote do not adjust the headphone volume (which i'm using as a line out)

I am planning to write a simple app to adjust the headphone volume whenever the mast volume is changed, but i can't seem to figure out how to get or set the headphone volume, as the audio manager deals with streams rather than outputs, so the only value i can get from it is the master.

How do I go about finding a way to get/set the headphone volume? I have got shell access through adb, but i cannot get root.

for reference the tv is running the latest firmware, which is android 5.1.1

James Kent
  • 5,763
  • 26
  • 50
  • 1
    android does not have a distinction between master and headphones output. You can only adjust streams https://developer.android.com/reference/android/media/AudioManager.html#adjustStreamVolume(int,%20int,%20int) – njzk2 Oct 31 '16 at 20:37
  • i know that ordinarily it doesn't, but somehow the manufacturer of this TV has managed to twin the outputs so that the headphones are always active, and the volume is controlled separately, this is widely noted on support forums, some Sony TVs have this issue too: http://www.supportforum.philips.com/en/archive/index.php/t-1361.html – James Kent Oct 31 '16 at 20:40
  • I think the TV headphone output is only for audio from HDMI input, is that correct? – Gabriel Fair Nov 10 '16 at 15:59
  • no, whatever audio the tv is playing (whether from HDMI in, TV input, scart etc) is played out through both the tv speakers and headphones at the same time, with a separate volume control for each – James Kent Nov 10 '16 at 16:27
  • To what port of your Philips 49PUS6401 surround sound system was connected "Headphones" or "Digital Audio Out" or else? – Andrii Omelchenko Nov 10 '16 at 17:36
  • And what surround sound system You are use? – Andrii Omelchenko Nov 10 '16 at 17:42
  • so if you " .. want to connect a surround sound system " to your TV , why your headphones are not pluged-in audio system ?? why to use headphones with TV ? did i miss something ?? I have at home the same configuration, and I use audio system remote for headphones when children sleep :) – CristiC777 Nov 11 '16 at 08:51
  • my sound system does not have a digital audio input, and the TV only has the headphones as an analog audio output, so my surround sound system is plugged into the headphones (i know then it's only stereo, but much better audio quality than built in) – James Kent Nov 11 '16 at 11:41
  • also the sound system does not have a remote control – James Kent Nov 11 '16 at 11:42
  • @JamesKent, did you manage to solve this problem? I just bought a 43PUS6501 and bumped into the same thing. – Attila Szasz Nov 23 '16 at 14:54
  • so far i have not managed to make any progress, personally if you are only using stereo i would suggest you buy an ARC receiver, they can be had for about £30 from amazon, finding a 5.1 surround version has proved more tricky so far... for stereo i found: https://www.amazon.co.uk/eSynic-Extractor-Converter-Function-1080p-Black/dp/B01LXOJCGJ/ref=sr_1_123?ie=UTF8&qid=1480003236&sr=8-123&keywords=hdmi+arc+output and for 5.1 i found: https://www.amazon.co.uk/switcher-Amplifier-Belfen-Supports-Extractor/dp/B01GC8HGMS/ref=sr_1_67?ie=UTF8&qid=1480002951&sr=8-67&keywords=hdmi%2Barc%2Boutput&th=1 – James Kent Nov 24 '16 at 16:02

1 Answers1

1

As I understand it is common issue of Philips Android TV users (for example p. 22 in this thread, or that discussion). In general, template for your task is Service which tracking plug/unplug event and volume of "system/music" audio stream (or media button press) than make corresponding changes on "wired headphones" audio "stream" (there is no such stream in "standard" Android, but obviously something like that present in "Android Philips") level. The issue is that seems to be impossible change volume "wiredheadphones" audio stream level using only Android SDK without "Philips Android TV API" (probably it's not a public).

Template source code for "VolumeTrackingService" may be something like this:

public class VolumeTrackingService extends Service {

    private static final String TAG = VolumeTrackingService.class.getSimpleName();

    public static final String ACTION_START = "VolumeTrackingService.ACTION_START";
    public static final String ACTION_STOP = "VolumeTrackingService.ACTION_STOP";

    HeadsetPlugIntentReceiver mHeadsetPlugReceiver;
    private static boolean mHeadsetPlugged = false;

    private SettingsContentObserver mSettingsContentObserver;

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mHeadsetPlugReceiver = new HeadsetPlugIntentReceiver();
        registerReceiver(mHeadsetPlugReceiver, new IntentFilter(Intent.ACTION_HEADSET_PLUG));
        mSettingsContentObserver = new SettingsContentObserver(new Handler());
        getApplicationContext().getContentResolver().registerContentObserver(android.provider.Settings.System.CONTENT_URI, true, mSettingsContentObserver);
    }

    @Override
    public void onDestroy() {
        getApplicationContext().getContentResolver().unregisterContentObserver(mSettingsContentObserver);
        unregisterReceiver(mHeadsetPlugReceiver);
        super.onDestroy();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        if (intent != null) {
            String actionRequested = intent.getAction();
            if (ACTION_START.equals(actionRequested)) {
            } else if (ACTION_STOP.equals(actionRequested)) {
                stopSelf();
            }
        }
        return START_STICKY;
    }

    private int getSystemVolumeInPercentage() {
        AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        final int streamVolumeMax = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
        final int streamVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
        return 100 * streamVolume / streamVolumeMax;
    }

    private void setHeadphonesVolume(int volumeInPercentage) {
        // there should be magic of wired headphones volume level changing
    }

    private void processVolumeChanges() {
        if (mHeadsetPlugged) {
            int systemVolumeInPercentage = getSystemVolumeInPercentage();
            setHeadphonesVolume(systemVolumeInPercentage);
        }
    }


    public class SettingsContentObserver extends ContentObserver {

        public SettingsContentObserver(Handler handler) {
            super(handler);
        }

        @Override
        public boolean deliverSelfNotifications() {
            return super.deliverSelfNotifications();
        }

        @Override
        public void onChange(boolean selfChange) {
            super.onChange(selfChange);
            if (mHeadsetPlugged ) {
                processVolumeChanges();
            }
        }
    }

    public class HeadsetPlugIntentReceiver extends android.content.BroadcastReceiver {
        @Override
        public void onReceive(Context ctx, Intent intent) {
            if (intent.getAction().equals(android.media.AudioManager.ACTION_HEADSET_PLUG)) {
                mHeadsetPlugged = intent.getIntExtra("state", 0) == 1;
            }
        }
    }
}

unfortunately it not solves main issue: changing volume level of wired headphones (probably it's impossible without "Philips Android TV API").

But if your surround sound system has remote control You can do some workaround: emulate sound system remote control commands in Service described above and send it via IR dongle connected to USB Host of your Philips 49PUS6401 Android TV.

Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79
  • while i do appreciate you taking the time to write a simple framework to help me, its the `// there should be magic of wired headphones volume level changing` bit i'm struggling with... – James Kent Nov 11 '16 at 16:30
  • I'm understand ) . Actually, I think "But if your surround sound system has remote control You can do some workaround: emulate sound system remote control commands in Service described above and send it via IR dongle connected to USB Host of your Philips 49PUS6401 Android TV." - is main part of answer, service template - just intro. I think no way to do what You want with only common Android SDK. – Andrii Omelchenko Nov 11 '16 at 17:07
  • And volume control of your surround sound system via simulate remote control signals will woks in any case. And IR dongle may be simple and cheap, like [this](http://www.huitsing.nl/irftdi/) It is 100% solution. Because issue is in Philips Android TV (for example on SONY BRAVIA everything works as You wish). – Andrii Omelchenko Nov 11 '16 at 17:15
  • my sound system does not have a remote control, so that won't work for me, it might for other people, but unfortunately this does not solve my problem. – James Kent Nov 14 '16 at 08:22
  • Ok. You can also try simulate "key press" event sequences to change headphone volume (like in [this](http://stackoverflow.com/a/17316047/6950238) answer), but it will be visible on the TV screen. But better add amplifier with volume control between TV and sound system . – Andrii Omelchenko Nov 14 '16 at 08:51
  • firing key events changes the main volume not the headphone volume – James Kent Nov 15 '16 at 13:34
  • But better add amplifier with volume control (or controlled attenuator) between TV and sound system and control it via TVs USB. – Andrii Omelchenko Nov 15 '16 at 14:09
  • there is an amplifier on the external speakers, it just doesn't have a remote – James Kent Nov 16 '16 at 09:26
  • Ok, I think You just need something between TV and external speakers which able to be controlled programmatically. – Andrii Omelchenko Nov 16 '16 at 09:36
  • i admit that a hardware solution is one option, bu this has got to be possible within the TV, it can control the main volume and the headphone volume, so it must be possible to programatically interact with them... – James Kent Nov 16 '16 at 09:37
  • Yes, its 100% possible, but seems only with "Android Philips SDK" because there is no separate audio stream for headphones in "standard" Android SDK. – Andrii Omelchenko Nov 16 '16 at 09:59