4

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?

mfiore
  • 321
  • 3
  • 16

1 Answers1

10

A playback category should not obey the mute switch

AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
AVAudioSession.sharedInstance().setActive(true)
Daniel Broad
  • 2,512
  • 18
  • 14
  • Doesn't work for me, my video is fine and the player is not muted and the volume is at max too. – Reza.Ab May 16 '18 at 16:35