-
Notifications
You must be signed in to change notification settings - Fork 1
Audio Session
This feature appeared in response to many user's requests.
The main goal is to ignore iPhone “silent” switch. This is achievable with the ISN_AVAudioSession.
In order for your device to play sounds even if iPhone currently in a silent mode, you need to activate audio session and change category to ISN_AVAudioSessionCategory.Playback. The code snippet below should do the trick:
using SA.iOS.AVFoundation;
...
ISN_AVAudioSession.SetActive(true);
ISN_AVAudioSession.SetCategory(ISN_AVAudioSessionCategory.Playback);
If you are using other native plugin's that allow you to play some audio or a youtube video, the audio session category can change. So you probably want to restore it to ISN_AVAudioSessionCategory.Playback once you have returned back to Unity.
Another Option might be to subscribe to an audio session OnAudioSessionRouteChange event and in case category was changed, just change it back:
using SA.iOS.AVFoundation;
...
ISN_AVAudioSession.OnAudioSessionRouteChange.AddListener((reason) => {
if(reason == ISN_AVAudioSessionRouteChangeReason.CategoryChange) {
ISN_AVAudioSession.SetActive(true);
ISN_AVAudioSession.SetCategory(ISN_AVAudioSessionCategory.Playback);
}
});
To be hornets it's absolutely not advisable, but who am I to say you can't do it. You may have a good reason to be playing sounds or music when a user device is in a "silent" mode.
Reliable and high-quality Unity Development service. Let's Talk!
Website | AssetStore | LinkedIn | Youtube | Scripting Reference
- Getting Started
- Authentication
- Game Center UI
- Leaderboards
- Default Leaderboard
- Achievements
- Saving A Game
- Access Point
- iTunes Connect Setup
- StoreKit Initialization
- Purchase flow
- Receipt Validation
- Store Review Controller
- Storefront API
- Subscription Offers