Ale*_*ier 16 avfoundation ios mpnowplayinginfocenter swift
我正在尝试使用MPMoviePlayerController为Swift中的iOS应用播放视频.
我的目标是能够播放系统音乐,如苹果音乐,然后打开我的应用程序,并将音频混合,但我希望我的应用程序能够控制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
}
}
Run Code Online (Sandbox Code Playgroud)
当我不想同时使用选项(.MixWithOthers)播放外部音乐时,上述功能有效,但是当我尝试使用选项(.MixWithOthers)播放外部音乐时,信息中心不会更新.
编辑1:为了让事情变得非常清楚,我已经正常播放视频我正在尝试使用其他背景音频播放视频,同时能够设置MPNowPlayingInfoCenter.
目前在iOS中无法实现.即使只是更改类别选项也会.MixWithOthers导致您nowPlayingInfo被忽略.
我的猜测是iOS只考虑包含非混音应用程序MPNowPlayingInfoCenter,因为如果有多个混音应用程序同时播放,那么(例如)控制中心会显示哪个应用程序会出现不确定性.
如果iOS使用尽力而为的方法来选择"正在播放的应用程序",我非常喜欢它,如下所示:
如果您也喜欢这种行为,我建议您向Apple提交一个错误.
| 归档时间: |
|
| 查看次数: |
2223 次 |
| 最近记录: |