xbmc / Official-Kodi-Remote-iOS

Full-featured remote control for XBMC Media Center. It features library browsing, now playing informations and a direct remote control.
Other
220 stars 104 forks source link

TF feedback: volume buttons like in YATSE #441

Open kambala-decapitator opened 2 years ago

kambala-decapitator commented 2 years ago

VOLUME BUTTONS SHOULD CONTROL KODI LIKE YATSE DOES ON ANDROID!!!!!!!!

wutschel commented 2 years ago

Sounds like https://github.com/xbmc/Official-Kodi-Remote-iOS/issues/263, https://github.com/xbmc/Official-Kodi-Remote-iOS/issues/41 or https://github.com/xbmc/Official-Kodi-Remote-iOS/issues/25.

wutschel commented 2 years ago

@kambala-decapitator, am I understanding correctly that iOS does not allow or at least Apple does not want Apps to take control of the hardware keys? In this case we cannot implement this request and #24. For a solution via a widget we have two other issues created.

kambala-decapitator commented 2 years ago

I don't think there's a dedicated public API, but you could try something like https://stackoverflow.com/questions/40231220/get-notification-on-volume-button-press-event-in-ios or even subclass UIApplication and check if there's any special event for volume buttons

wutschel commented 2 years ago

Thanks. As a first attempt to play around with this I added the relevant code to the volume handling controller of the App. Can you point me to why observeValueForKeyPath is not called when I press the HW volume key? I guess I am missing something when adding the observer. Code: https://github.com/wutschel/Official-Kodi-Remote-iOS/commit/126e08aef2d8f32d4152db9707663cdd83e249fb

kambala-decapitator commented 2 years ago

The code seems fine, maybe this approach no longer works.

Just in case make sure that audio session succeeds in becoming active.

wutschel commented 2 years ago

No, doesn't seem so. I used a method which is called once per second and called:

AVAudioSession* audioSession = [AVAudioSession sharedInstance];
[audioSession setActive:YES error:nil];
currentiOSVolume = audioSession.outputVolume;

If I change the volume, I can read proper values (0.0 -> 1.0).

Now I only call above sequence once and then repeated each second:

AVAudioSession* audioSession = [AVAudioSession sharedInstance];
currentiOSVolume = audioSession.outputVolume;

The values keep the same as for the first call.

kambala-decapitator commented 2 years ago

strange, audio session activation needs to be done only once afaik (unless you deactivate it later).

please also try this:

subclass UIApplication and check if there's any special event for volume buttons

wutschel commented 2 years ago

Nope, cannot get this working.

kambala-decapitator commented 2 years ago

just tested the following code on a few different devices - all works:

__auto_type audioSession = [AVAudioSession sharedInstance];
[audioSession setActive:YES error:NULL];
[audioSession addObserver:self forKeyPath:NSStringFromSelector(@selector(outputVolume)) options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:NULL];

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
    // the `change` dictionary contains correct values for old and new (current) volume level
}
wutschel commented 2 years ago

Can you share the complete change in a commit? And this works in simulator (setting a break point in observeValueForKeyPath and using the volume keys)?

kambala-decapitator commented 2 years ago

I tested this code in a test project (placed in applicationDidFinishLaunching), didn't care to check in simulator.