LoginSignup
1
4

More than 5 years have passed since last update.

iOSでUnity製アプリを起動したときに、別アプリで再生中の音楽が止まる問題の対策

Last updated at Posted at 2019-03-06

iOSでUnity製アプリを起動すると、プロジェクト設定によっては別アプリで再生中の音楽が止まる。この問題を応急処置的に対策する。

方法

iOSプロジェクト出力結果のUnityViewControllerBase.mmのviewWillAppearへ下記を追記する。

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryAmbient error:nil];
[audioSession setActive:YES error:nil];

今後の課題

  • プロジェクトを出力するたびに書き直す必要があるので、自動化が必要。
  • ネイティブプラグイン化について要調査

Androidの場合

Androidの場合は、対策しなくても音楽は止まらないため問題ない。

下記の設定によって、止まるようにできる。

  1. File > Build Settings を開く
  2. Player Settings のOther Settings にある"Mute Other Audio Sources" のチェックを入れる

※iOSでは、このチェックをどう設定しようと音楽が止まってしまう。

参考

[IOS] [FMOD] MUTE OTHER AUDIO SOURCES IS IGNORED WITH FMOD AND AUDIO>DISABLE UNITY AUDIO=TRUE
https://issuetracker.unity3d.com/issues/ios-fmod-mute-other-audio-sources-is-ignored-with-fmod-and-audio-disable-unity-audio-equals-true

Unityで開発したiOSアプリがサイレントモードでも音がなる時の対処法
https://aozolabo.wordpress.com/2015/01/31/issue-silentmode-on-ios/

1
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
4