Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVPlayer does not sound if disabled audio / vibration: on

Hy, I'm trying to understand if there is a way to get sound from the player even when your iPhone is set to silent .. Is there a Swift code to enable the Tone?

//IMPOSRT FOUNDATION PER PLAYER
import AVFoundation

        let url = NSURL(string: "https://mywebsite.site/file/\(audio_r!)")
        playerItem = AVPlayerItem(URL: url!)
        player = AVPlayer(playerItem: playerItem!)
        let playerLayer = AVPlayerLayer(player: player!)
        playerLayer.frame = CGRectMake(0,0,300,50)
        self.view.layer.addSublayer(playerLayer)
        //imposto il volume
        player!.muted = false
        player!.volume = 1.0

Someone can help me?

like image 564
mfiore Avatar asked Dec 25 '22 00:12

mfiore


1 Answers

A playback category should not obey the mute switch

AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
AVAudioSession.sharedInstance().setActive(true)
like image 131
Daniel Broad Avatar answered Dec 28 '22 08:12

Daniel Broad