Skip to content

Commit

Permalink
Merge pull request #2 from kkostov/fix-playback-on-ios-dnd-mode
Browse files Browse the repository at this point in the history
fix: play despite dnd mode on iOS by setting AVAudioSession category
  • Loading branch information
kkostov authored Oct 31, 2024
2 parents beaaa5a + f9afcf8 commit 68b526f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion gadulka/src/iosMain/kotlin/GadulkaAudioPlayer.ios.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package eu.iamkonstantin.kotlin.gadulka

import kotlinx.cinterop.ExperimentalForeignApi
import platform.AVFoundation.*
import platform.Foundation.NSURL
import platform.AVFAudio.AVAudioSession
import platform.AVFAudio.AVAudioSessionCategoryPlayback

actual class GadulkaPlayer {
private var player: AVPlayer? = null

@OptIn(ExperimentalForeignApi::class)
actual fun play(url: String) {
release()

AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, null)
val nsUrl = NSURL(string = url)
player = AVPlayer.playerWithURL(nsUrl)
player?.play()
Expand Down

0 comments on commit 68b526f

Please sign in to comment.