我正在尝试使用MPMoviePlayerController在Swift的iOS应用中播放视频。
我的目标是能够使用类似于Apple Music的系统音乐播放,并打开我的应用程序,让音频混合,但是我希望我的应用程序能够控制MPNowPlayingInfoCenter。
如何在使用AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, withOptions: .MixWithOthers)的同时设置MPNowPlayingInfoCenter?
Google Maps在设置MPNowPlayingInfoCenter的同时混合音频。以下是我尝试设置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的同时播放其他背景音频。