
blog.kulman.sk/correctly-playing-audio-in-ios-apps
Preview meta tags from the blog.kulman.sk website.
Linked Hostnames
6- 14 links toblog.kulman.sk
- 2 links togithub.com
- 1 link tobuymeacoffee.com
- 1 link togohugo.io
- 1 link tohachyderm.io
- 1 link tolinkedin.com
Search Engine Appearance
Correctly playing audio in iOS applications
When you look for a way to play audio in your iOS application you usually find code like this player = try AVAudioPlayer(contentsOf: url) player.prepareToPlay() player.play() While this code works and will play the given audio file it does not deal with all the nuances of audio playback. Imagine the user is playing a podcast or music, do you want the sound in your app to stop that playback? Or play over it? The key to correct audio playback is understanding AVAudioSession categories. Let’s take it by example Playing ambient sounds over existing audio If you want to play an audio file in your application without affecting the existing music or podcast playback that might be going on you should use the .ambient category. You use this category for example to play sound effects like the sound of a message being sent in a chat application where the sound is not that important and definitely not worth affecting other playback in iOS. You set the category on the shared AVAudioSession instance try AVAudioSession.sharedInstance().setCategory(.ambient, mode: .default) and make it active try AVAudioSession.sharedInstance().setActive(true) All the sounds you now play using AVAudioPlayer will be played as ambient sounds. Stopping existing audio to play your sound If the audio file you want to play in your application is important, for example playing a received voice message in a chat application, you can stop existing audio that is playing on iOS. You can achieve this by setting the category to .playback try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default) try AVAudioSession.sharedInstance().setActive(true) Remember, setting a category makes it persist for all the consecutive audio playback until you set it to a different value. When you play a sound now using AVAudioPlayer it will stop the music or podcast the user might be listening to. But what if you want the users music or podcast to continue after you play your sound?
Bing
Correctly playing audio in iOS applications
When you look for a way to play audio in your iOS application you usually find code like this player = try AVAudioPlayer(contentsOf: url) player.prepareToPlay() player.play() While this code works and will play the given audio file it does not deal with all the nuances of audio playback. Imagine the user is playing a podcast or music, do you want the sound in your app to stop that playback? Or play over it? The key to correct audio playback is understanding AVAudioSession categories. Let’s take it by example Playing ambient sounds over existing audio If you want to play an audio file in your application without affecting the existing music or podcast playback that might be going on you should use the .ambient category. You use this category for example to play sound effects like the sound of a message being sent in a chat application where the sound is not that important and definitely not worth affecting other playback in iOS. You set the category on the shared AVAudioSession instance try AVAudioSession.sharedInstance().setCategory(.ambient, mode: .default) and make it active try AVAudioSession.sharedInstance().setActive(true) All the sounds you now play using AVAudioPlayer will be played as ambient sounds. Stopping existing audio to play your sound If the audio file you want to play in your application is important, for example playing a received voice message in a chat application, you can stop existing audio that is playing on iOS. You can achieve this by setting the category to .playback try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default) try AVAudioSession.sharedInstance().setActive(true) Remember, setting a category makes it persist for all the consecutive audio playback until you set it to a different value. When you play a sound now using AVAudioPlayer it will stop the music or podcast the user might be listening to. But what if you want the users music or podcast to continue after you play your sound?
DuckDuckGo

Correctly playing audio in iOS applications
When you look for a way to play audio in your iOS application you usually find code like this player = try AVAudioPlayer(contentsOf: url) player.prepareToPlay() player.play() While this code works and will play the given audio file it does not deal with all the nuances of audio playback. Imagine the user is playing a podcast or music, do you want the sound in your app to stop that playback? Or play over it? The key to correct audio playback is understanding AVAudioSession categories. Let’s take it by example Playing ambient sounds over existing audio If you want to play an audio file in your application without affecting the existing music or podcast playback that might be going on you should use the .ambient category. You use this category for example to play sound effects like the sound of a message being sent in a chat application where the sound is not that important and definitely not worth affecting other playback in iOS. You set the category on the shared AVAudioSession instance try AVAudioSession.sharedInstance().setCategory(.ambient, mode: .default) and make it active try AVAudioSession.sharedInstance().setActive(true) All the sounds you now play using AVAudioPlayer will be played as ambient sounds. Stopping existing audio to play your sound If the audio file you want to play in your application is important, for example playing a received voice message in a chat application, you can stop existing audio that is playing on iOS. You can achieve this by setting the category to .playback try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default) try AVAudioSession.sharedInstance().setActive(true) Remember, setting a category makes it persist for all the consecutive audio playback until you set it to a different value. When you play a sound now using AVAudioPlayer it will stop the music or podcast the user might be listening to. But what if you want the users music or podcast to continue after you play your sound?
General Meta Tags
11- titleCorrectly playing audio in iOS applications - Igor Kulman
- charsetutf-8
- X-UA-CompatibleIE=edge
- viewportwidth=device-width, initial-scale=1, shrink-to-fit=no
- theme-color
Open Graph Meta Tags
4- og:titleCorrectly playing audio in iOS applications
- og:descriptionWhen you look for a way to play audio in your iOS application you usually find code like this player = try AVAudioPlayer(contentsOf: url) player.prepareToPlay() player.play() While this code works and will play the given audio file it does not deal with all the nuances of audio playback. Imagine the user is playing a podcast or music, do you want the sound in your app to stop that playback? Or play over it? The key to correct audio playback is understanding AVAudioSession categories. Let’s take it by example Playing ambient sounds over existing audio If you want to play an audio file in your application without affecting the existing music or podcast playback that might be going on you should use the .ambient category. You use this category for example to play sound effects like the sound of a message being sent in a chat application where the sound is not that important and definitely not worth affecting other playback in iOS. You set the category on the shared AVAudioSession instance try AVAudioSession.sharedInstance().setCategory(.ambient, mode: .default) and make it active try AVAudioSession.sharedInstance().setActive(true) All the sounds you now play using AVAudioPlayer will be played as ambient sounds. Stopping existing audio to play your sound If the audio file you want to play in your application is important, for example playing a received voice message in a chat application, you can stop existing audio that is playing on iOS. You can achieve this by setting the category to .playback try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default) try AVAudioSession.sharedInstance().setActive(true) Remember, setting a category makes it persist for all the consecutive audio playback until you set it to a different value. When you play a sound now using AVAudioPlayer it will stop the music or podcast the user might be listening to. But what if you want the users music or podcast to continue after you play your sound?
- og:typearticle
- og:urlhttps://blog.kulman.sk/correctly-playing-audio-in-ios-apps/
Twitter Meta Tags
3- twitter:cardsummary
- twitter:titleCorrectly playing audio in iOS applications
- twitter:descriptionWhen you look for a way to play audio in your iOS application you usually find code like this player = try AVAudioPlayer(contentsOf: url) player.prepareToPlay() player.play() While this code works and will play the given audio file it does not deal with all the nuances of audio playback. Imagine the user is playing a podcast or music, do you want the sound in your app to stop that playback? Or play over it? The key to correct audio playback is understanding AVAudioSession categories. Let’s take it by example Playing ambient sounds over existing audio If you want to play an audio file in your application without affecting the existing music or podcast playback that might be going on you should use the .ambient category. You use this category for example to play sound effects like the sound of a message being sent in a chat application where the sound is not that important and definitely not worth affecting other playback in iOS. You set the category on the shared AVAudioSession instance try AVAudioSession.sharedInstance().setCategory(.ambient, mode: .default) and make it active try AVAudioSession.sharedInstance().setActive(true) All the sounds you now play using AVAudioPlayer will be played as ambient sounds. Stopping existing audio to play your sound If the audio file you want to play in your application is important, for example playing a received voice message in a chat application, you can stop existing audio that is playing on iOS. You can achieve this by setting the category to .playback try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default) try AVAudioSession.sharedInstance().setActive(true) Remember, setting a category makes it persist for all the consecutive audio playback until you set it to a different value. When you play a sound now using AVAudioPlayer it will stop the music or podcast the user might be listening to. But what if you want the users music or podcast to continue after you play your sound?
Item Prop Meta Tags
6- nameCorrectly playing audio in iOS applications
- descriptionWhen you look for a way to play audio in your iOS application you usually find code like this player = try AVAudioPlayer(contentsOf: url) player.prepareToPlay() player.play() While this code works and will play the given audio file it does not deal with all the nuances of audio playback. Imagine the user is playing a podcast or music, do you want the sound in your app to stop that playback? Or play over it? The key to correct audio playback is understanding AVAudioSession categories. Let’s take it by example Playing ambient sounds over existing audio If you want to play an audio file in your application without affecting the existing music or podcast playback that might be going on you should use the .ambient category. You use this category for example to play sound effects like the sound of a message being sent in a chat application where the sound is not that important and definitely not worth affecting other playback in iOS. You set the category on the shared AVAudioSession instance try AVAudioSession.sharedInstance().setCategory(.ambient, mode: .default) and make it active try AVAudioSession.sharedInstance().setActive(true) All the sounds you now play using AVAudioPlayer will be played as ambient sounds. Stopping existing audio to play your sound If the audio file you want to play in your application is important, for example playing a received voice message in a chat application, you can stop existing audio that is playing on iOS. You can achieve this by setting the category to .playback try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default) try AVAudioSession.sharedInstance().setActive(true) Remember, setting a category makes it persist for all the consecutive audio playback until you set it to a different value. When you play a sound now using AVAudioPlayer it will stop the music or podcast the user might be listening to. But what if you want the users music or podcast to continue after you play your sound?
- datePublished2022-04-21T05:29:12+01:00
- dateModified2022-04-21T05:29:12+01:00
- wordCount637
Link Tags
10- apple-touch-iconhttps://blog.kulman.sk/apple-touch-icon.png
- canonicalhttps://blog.kulman.sk/correctly-playing-audio-in-ios-apps/
- iconhttps://blog.kulman.sk/favicon.ico
- preloadhttps://blog.kulman.sk/theme.png
- preloadhttps://blog.kulman.sk/images/avatar.jpg
Links
20- https://blog.kulman.sk
- https://blog.kulman.sk/about
- https://blog.kulman.sk/automatically-merge-xcode-project-conflicts
- https://blog.kulman.sk/custom-areas-in-snapshots
- https://blog.kulman.sk/git-worktree