Created
May 3, 2019 22:17
-
-
Save standinga/f8e7f0793c3f545a5a4c635745c5c9ae to your computer and use it in GitHub Desktop.
ViewController.swift for medium post about Audio Unit V3 Extensions updated adding plugin view controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Cocoa | |
import AUFramework | |
class ViewController: NSViewController { | |
private var audioPlayer: AudioPlayer! | |
private var pluginVC: AudioUnitViewController! | |
@IBOutlet weak var auContainer: NSView! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
guard let url = Bundle.main.url(forResource: "z", withExtension: "wav") else { | |
fatalError("can't create url from resource") | |
} | |
audioPlayer = AudioPlayer(url) | |
addPluginView() | |
audioPlayer.play() | |
} | |
private func addPluginView() { | |
let builtInPluginsURL = Bundle.main.builtInPlugInsURL | |
guard let pluginURL = builtInPluginsURL?.appendingPathComponent("VolumePlugin.appex") else { | |
fatalError("cannot get plugin URL") | |
} | |
let appExtensionBundle = Bundle(url: pluginURL) | |
pluginVC = AudioUnitViewController(nibName: "AudioUnitViewController", bundle: appExtensionBundle) | |
let auView = pluginVC.view | |
auView.frame = auContainer.bounds | |
auContainer.addSubview(auView) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment