LoginSignup
8
7

More than 5 years have passed since last update.

自作ミュージックアプリで MPRemoteCommandCenter と MPNowPlayingInfoCenter が機能しなくて悩んだ

Last updated at Posted at 2016-07-13

ロック画面に再生中楽曲の情報が表示されないという現象に悩まされました。結局のところ AVAudioSession のカテゴリーオプションを .DuckOthers としていたのが原因で、これは .DefaultToSpeaker にしないとだめなようです。

let session = AVAudioSession.sharedInstance()
do {
    try session.setCategory(AVAudioSessionCategoryPlayback, withOptions: .DefaultToSpeaker)
}
catch {}

Background Modes の Audio, AirPlay and Picture in Picture も有効にしておきましょう。

MPRemoteCommandCenter, MPNowPlayingInfoCenter とは

それぞれ MediaPlayer フレームワークのクラスです。

  • MPRemoteCommandCenter
    ロック画面やコントロールセンターなどから音楽の遠隔操作をできるようにするためのイベントハンドラーです。remoteControlReceivedWithEvent(event: UIEvent?) を使うやり方もありますがこれは 7.0 までの古い仕組みらしく、よりモダンなこちらの方が便利だと思います。

  • MPNowPlayingInfoCenter
    再生中楽曲の情報を表示するためのクラスです。AirPlay している Apple TV でも使われます。

8
7
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
8
7