5

i want to set Iphone Speaker default. My volume control swift code is below. It is works fine but when i tapped airplay button i see automatically select the second.(Iphone)

var wrapperView = UIView(frame: CGRectMake(10,40,(self.view.bounds.size.width)-20, 20))           
        wrapperView.backgroundColor=UIColor.purpleColor()         
        self.view.addSubview(wrapperView)       
        var volumeView = MPVolumeView(frame: wrapperView.bounds)
        volumeView.tintColor=UIColor.purpleColor()  
        wrapperView.addSubview(volumeView)

airplay button options

davudi
  • 117
  • 3
  • 13
  • I have custom player based on AVPlayer. And I need to show AirPlay button. I try to use the same code, but got only purpleColor rect without any controls. May be you can help me, why it happens? – Serhii Didanov Aug 06 '17 at 05:22

1 Answers1

1

Don't know if you've solved this... Just set the default to be to the speaker (add any others you want as well, eg Bluetooth, headphones...)

    do {
        try AVAudioSession.sharedInstance().setCategory(
            AVAudioSessionCategoryPlayAndRecord,
            withOptions: [.DefaultToSpeaker])
        success = true
    } catch _ {
    }
Agreensh
  • 1,305
  • 1
  • 12
  • 15