質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Objective-C

Objective-Cはオブジェクト指向型のプログラミング言語のひとつです。C言語をベースにSmalltalkが取り入れられています。

iOS

iOSとは、Apple製のスマートフォンであるiPhoneやタブレット端末のiPadに搭載しているオペレーションシステム(OS)です。その他にもiPod touch・Apple TVにも搭載されています。

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

iPhone

iPhoneとは、アップル社が開発・販売しているスマートフォンです。 同社のデジタルオーディオプレーヤーiPodの機能、電話機能、インターネットやメールなどのWeb通信機能の3つをドッキングした機器です。

Q&A

0回答

994閲覧

実機でMPNowPlayingInfoCenterによる曲情報表示やMPRemoteCommandCenterによる再生制御ができない

sirosiro

総合スコア26

Objective-C

Objective-Cはオブジェクト指向型のプログラミング言語のひとつです。C言語をベースにSmalltalkが取り入れられています。

iOS

iOSとは、Apple製のスマートフォンであるiPhoneやタブレット端末のiPadに搭載しているオペレーションシステム(OS)です。その他にもiPod touch・Apple TVにも搭載されています。

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

iPhone

iPhoneとは、アップル社が開発・販売しているスマートフォンです。 同社のデジタルオーディオプレーヤーiPodの機能、電話機能、インターネットやメールなどのWeb通信機能の3つをドッキングした機器です。

0グッド

0クリップ

投稿2018/05/25 02:50

以下が実機の情報

  • iOS 10.1.1
  • iPhone7

最初はApple Developer Programは無料版で実機転送しておりましたが、途中から年間契約に切り替えました。

シミュレーターによるデバッグ時はMPNowPlayingInfoCenterによる曲情報表示やMPRemoteCommandCenterによる再生制御ができていたのですが、実機に転送するとできません。(Apple提供のデフォルトの音楽再生アプリ「ミュージック」だけの制御ができる状態)

以下がコードです。
application didFinishLaunchingWithOptionsにて実行しています。

objective

1__weak MPRemoteCommandCenter *commandCenter = [MPRemoteCommandCenter sharedCommandCenter]; 2commandCenter.changePlaybackPositionCommand.enabled = false; 3[commandCenter.changePlaybackPositionCommand addTarget:self 4 action:@selector(changedThumbSlider:)]; 5 6commandCenter.playCommand.enabled = false; 7commandCenter.pauseCommand.enabled = false; 8commandCenter.nextTrackCommand.enabled = false; 9commandCenter.previousTrackCommand.enabled = false; 10[commandCenter.playCommand addTarget:self action:@selector(play:)]; 11[commandCenter.pauseCommand addTarget:self action:@selector(pause:)]; 12[commandCenter.nextTrackCommand addTarget:self action:@selector(next:)]; 13[commandCenter.previousTrackCommand addTarget:self action:@selector(prev:)]; 14 15NSError *error = nil; 16__weak AVAudioSession *session = nil; 17session = [AVAudioSession sharedInstance]; 18 19[session setCategory:AVAudioSessionCategoryPlayback 20 withOptions:AVAudioSessionCategoryOptionMixWithOthers | 21 AVAudioSessionCategoryOptionDuckOthers 22 error:&error]; 23if (error) { 24 [self showError:error title:@"AudioSessionカテゴリ設定エラー"]; 25 return; 26} 27 28[_logs addObject:@"+Session Activate"]; 29error = nil; 30[session setActive:true 31 error:&error]; 32if (error) { 33 [self showError:error title:@"AudioSessionアクティベートエラー"]; 34 return; 35}

以下は曲の再生開始時に実行しています。

objective

1 __strong NSMutableDictionary *songInfo = nil; 2 __strong Media *media = self.currentMedia; 3 4 // music information 5 songInfo = [[NSMutableDictionary alloc] init]; 6 Float64 duration = CMTimeGetSeconds(self.queuePlayer.currentItem.duration); 7 Float64 elapsed = CMTimeGetSeconds(self.queuePlayer.currentTime); 8 [songInfo setObject:media.title forKey:MPMediaItemPropertyTitle]; 9 [songInfo setObject:media.album forKey:MPMediaItemPropertyAlbumTitle]; 10 [songInfo setObject:media.author forKey:MPMediaItemPropertyArtist]; 11 [songInfo setObject:[NSNumber numberWithFloat:1.0f] 12 forKey:MPNowPlayingInfoPropertyPlaybackRate]; 13 [songInfo setObject:[NSNumber numberWithDouble:duration] 14 forKey:MPMediaItemPropertyPlaybackDuration]; 15 [songInfo setObject:[NSNumber numberWithDouble:elapsed] 16 forKey:MPNowPlayingInfoPropertyElapsedPlaybackTime]; 17 18 MPMediaItemArtwork *artwork = nil; 19 __strong UIImage *thumbnailImage = media.thumbnailImage; 20 artwork = [[MPMediaItemArtwork alloc] initWithBoundsSize:thumbnailImage.size 21 requestHandler:^UIImage * _Nonnull(CGSize size) { 22 return thumbnailImage; 23 }]; 24 [songInfo setObject:artwork forKey:MPMediaItemPropertyArtwork]; 25 26 // update 27 __weak MPNowPlayingInfoCenter *nowPlayingInforCenter = nil; 28 nowPlayingInforCenter = [MPNowPlayingInfoCenter defaultCenter]; 29 [nowPlayingInforCenter setNowPlayingInfo:nil]; 30 [nowPlayingInforCenter setNowPlayingInfo:songInfo]; 31 artwork = nil; 32 songInfo = nil;

Capabilitiesの設定は、

  • Background Modes は ON
  • Audio, AirPlay, and Picture in Pictureにチェック
  • Background fetchにチェック
  • Remote notificationsにチェック

の状態です。

同様の現象が発生して解決された方はいらっしゃいませんか?

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問