Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use system channel instead of ringer channel when using EPSSampler in iOS

I'm using EPSSampler to play some notes in my tiny iOS app. It works nicely, except that the sound is controlled through the ringer settings instead of the system volume settings. The problem is that, if the ringer is turned off, my app makes no sound.

The closest I could find was this SO question but I can't quite translate that solution into mine, as I can't match it to EPSSampler's code. Any insight?

EDIT To clarify, the only code that deals specifically with audio is contained in the EPSSampler class, my app merely instances it, loads an AUSampler preset, and calls the note-playing methods in EPSSampler, so a solution would need to change something in EPSSampler rather than in my app -- that's why I'm not posting any source code.

like image 278
Morpheu5 Avatar asked Sep 14 '17 16:09

Morpheu5


1 Answers

Turns out this had nothing to do with EPSSampler, and everything with configuring the audio session. The following code did the trick.

NSError *error = nil;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&error];

That'll teach me to RTFM.

like image 188
Morpheu5 Avatar answered Oct 31 '22 10:10

Morpheu5