Swift の iOS アプリで MPMoviePlayerController を使用してビデオを再生しようとしています。
私の目標は、Apple Music などでシステム ミュージックを再生し、アプリを開いてオーディオをミックスできるようにすることですが、アプリでMPNowPlayingInfoCenter
.
AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, withOptions: .MixWithOthers)
MPNowPlayingInfoCenter を設定したまま使用するにはどうすればよいですか?
MPNowPlayingInfoCenter の設定中に、Google マップが音声をミックスします。以下は、MPNowPlayingInfoCenter を設定しようとしている方法です。
func setMeta(){
UIApplication.sharedApplication().beginReceivingRemoteControlEvents()
self.becomeFirstResponder()
if let player = PlayWorkoutViewController.player{
let coverArt = MPMediaItemArtwork(image: UIImage(named: "AlbumArt")!)
let dict: [String: AnyObject] = [
MPMediaItemPropertyArtwork: coverArt,
MPMediaItemPropertyTitle:workout.title,
MPMediaItemPropertyArtist:"Alex",
MPMediaItemPropertyAlbumTitle:workout.program.title,
MPNowPlayingInfoPropertyPlaybackRate: player.currentPlaybackRate,
MPNowPlayingInfoPropertyElapsedPlaybackTime: player.currentPlaybackTime,
MPMediaItemPropertyPlaybackDuration: player.playableDuration
]
MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo = dict
}
}
上記の機能は、オプション ( ) を使用して同時に外部音楽を再生しようとしていないときに機能しますが、オプション ( ) を使用して外部音楽を再生しようとしている間は、情報センターが更新されません。.MixWithOthers
.MixWithOthers
編集1:非常に明確にするために、私はすでにビデオを適切に再生しています.MPNowPlayingInfoCenterを設定しながら、他のバックグラウンドオーディオでビデオを再生しようとしています.