简体   繁体   中英

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. If the other app has a mixable session, then it will continue. 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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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