AVAudioSession is unavailable in macOS 14 Sonoma

151 Views Asked by At

AVAudioSession is deprecated in macOS 13 Ventura and unavailable in macOS 14 Sonoma. How can I easily get audio output routes as I would with AVAudioSession.sharedInstance().currentRoute()? I have the following Swift code:

import AppKit
import AVFoundation

class ViewController: NSViewController {

    private var audioSession: AVAudioSession!

    override func viewDidLoad() {
        super.viewDidLoad()

        // Initialize the audio session.
        audioSession = AVAudioSession.sharedInstance()

        // Get a list of all audio routes on the device.
        let audioRoutes = audioSession.currentRoutes

        // For each audio route, print the route name and the app name.
        for audioRoute in audioRoutes {
            print("Route name: \(audioRoute.name)")
            print("App name: \(audioRoute.sourcePortName)")
        }
    }
}

Expecting to return something like:

Route name: Built-in Speaker
App name: Spotify

Route name: Headphones
App name: Teams

Route name: Display Audio
App name: Chrome

Already tried to find something in AppKit or AVFoundation frameworks but no luck on that.

EDIT: I'm trying to create a simple app to manage the volume of apps running on the device individually with some sliders, but first I was just trying to list the audio routes output

0

There are 0 best solutions below