简体   繁体   English

Swift 停止系统音频

[英]Swift Stop System Audio

I'm developing a Sleep Timer App.我正在开发一个睡眠定时器应用程序。 As soon as the timer is done, I want to stop the audio on the device.计时器一结束,我就想停止设备上的音频。 Is there any way to stop the system Sound or do I have to play a silent audio file?有什么方法可以停止系统声音,还是必须播放无声音频文件?

I already tried this Code:我已经尝试过这段代码:

do {
     try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playback)
     try AVAudioSession.sharedInstance().setActive(true) 
} catch { print(error.localizedDescription) }

.playback will only pause non-mixable sessions. .playback只会暂停不可混合的会话。 If the other app has a mixable session, then it will continue.如果另一个应用程序有一个可混合的 session,那么它将继续。 The only mode that will pause mixable sessions is .record (which will require that you request recording permission, even though you're not going to use it).唯一会暂停可混合会话的模式是.record (这将需要您请求录制许可,即使您不打算使用它)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM