Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TF feedback: volume buttons like in YATSE #441

Open
kambala-decapitator opened this issue Oct 30, 2021 · 11 comments
Open

TF feedback: volume buttons like in YATSE #441

kambala-decapitator opened this issue Oct 30, 2021 · 11 comments
Labels

Comments

@kambala-decapitator
Copy link
Collaborator

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

@wutschel
Copy link
Collaborator

Sounds like #263, #41 or #25.

@wutschel
Copy link
Collaborator

wutschel commented Jan 8, 2022

@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
Copy link
Collaborator Author

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
Copy link
Collaborator

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: wutschel@126e08a

@kambala-decapitator
Copy link
Collaborator Author

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

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

@wutschel
Copy link
Collaborator

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
Copy link
Collaborator Author

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
Copy link
Collaborator

Nope, cannot get this working.

@kambala-decapitator
Copy link
Collaborator Author

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
Copy link
Collaborator

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
Copy link
Collaborator Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants