Open kambala-decapitator opened 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.
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
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
The code seems fine, maybe this approach no longer works.
Just in case make sure that audio session succeeds in becoming active.
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.
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
Nope, cannot get this working.
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
}
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)?
I tested this code in a test project (placed in applicationDidFinishLaunching
), didn't care to check in simulator.
VOLUME BUTTONS SHOULD CONTROL KODI LIKE YATSE DOES ON ANDROID!!!!!!!!