Play Audio when device in silent mode – ios swift

Put this line before calling play() method of AVPlayer.

In Objective C

[[AVAudioSession sharedInstance]
            setCategory: AVAudioSessionCategoryPlayback
                  error: nil];

In Swift

do {
    try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
} catch {
    // report for an error
}

Swift 5

do {
    try AVAudioSession.sharedInstance().setCategory(.playback)
} catch(let error) {
    print(error.localizedDescription)
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)