Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i set MPVolumeView with swift?

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

like image 905
davudi Avatar asked Nov 09 '22 06:11

davudi


1 Answers

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 _ {
    }
like image 81
Agreensh Avatar answered Dec 24 '22 07:12

Agreensh