LoginSignup
5
1

[Swift]音声出力をスピーカに切り替える方法

Posted at
.swift
import AVFoundation
 
let audioSession = AVAudioSession.sharedInstance()
var isSpeaker = false

func hogehoge() {
    if isSpeaker {
        try? audioSession.overrideOutputAudioPort(.none)
        isSpeaker = false
    } else {
        try? audioSession.overrideOutputAudioPort(.speaker)
        isSpeaker = true
    }
}

これで音声出力を通常/スピーカーで切り替えることができます!

5
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
1