【发布时间】:2016-04-06 10:20:08
【问题描述】:
我正在尝试使用 MPMoviePlayerController 为 Swift 中的 iOS 应用播放视频。
我的目标是能够用苹果音乐之类的东西播放系统音乐,然后打开我的应用程序并混合音频,但我希望我的应用程序能够控制MPNowPlayingInfoCenter。
如何在设置 MPNowPlayingInfoCenter 的同时使用 AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, withOptions: .MixWithOthers)?
Google 地图在设置 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) 播放外部音乐,但我尝试使用选项播放外部音乐 (@ 987654325@) 信息中心没有更新。
编辑 1:只是为了让事情变得超级清楚,我已经可以正常播放视频我正在尝试使用其他背景音频播放视频,同时能够设置 MPNowPlayingInfoCenter。
【问题讨论】:
标签: ios swift avfoundation mpnowplayinginfocenter