ios – AVPlayer删除背景音乐

我一直在使用giffycat解码,存储和播放gifs在我的应用程序.我正在使它可以轻松地加载一个gif在UICollectionView的单元格,所以我已经决定每个gif模型有自己的AVPlayer.我注意到,通过创建一个AVPlayer,如下所示,其他应用程序的音频被杀死!烦人的用户和创作者!
// Create an AVURLAsset with an NSURL containing the path to the video
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:[NSURL URLWithString:_mp4] options:nil];
// Create an AVPlayerItem using the asset
AVPlayerItem *item = [AVPlayerItem playerItemWithAsset:asset];
_player = [AVPlayer playerWithPlayerItem:item]; //if this line is commented out,I hear audio,else audio from Spotify is quickly killed...

由于这些视频只是gif,我想知道是否有一些方法取消分配音频会话.我不太了解这个.请帮助!

解决方法

结果答案很简单,经过一番谷歌搜索和文档阅读后…
解决方案是
// audio session
let audioSession = AVAudioSession.sharedInstance()
try! audioSession.setCategory(AVAudioSessionCategoryAmbient,withOptions: AVAudioSessionCategoryOptions.MixWithOthers)

哎呀,只是意识到我在objC发布我的问题,并在Swift回答.很好,因为那是有时候的生活.

AudioSession是整个应用程序的单例,用于规划应用程序如何与系统和其他应用程序的其他声音混合!认音频会话是

>播放启用,录制被禁用
>当用户将静音开关移到“静音”时,您的音频被静音
>当用户按睡眠/唤醒按钮锁定屏幕或自动锁定期限到期时,您的音频被静音
>当您的音频启动时,设备上的其他音频(音乐)将被静音.

CategoryAmbient告诉它不要做4

很好的文档!
https://developer.apple.com/library/ios/documentation/Audio/Conceptual/AudioSessionProgrammingGuide/ConfiguringanAudioSession/ConfiguringanAudioSession.html#//apple_ref/doc/uid/TP40007875-CH2-SW1

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...