What is the View Hierachy and how can I add a MpVolumeView to it?

54 Views Asked by At

I'm attempting to add a mpvolumeview to my app to allow to select an output channel, however I'm struggling to understand the documentation.

By view Hierachy, I'm assuming that this is just this, where I've set the class to MpVolumeView, however it is not appearing.

The link is here: https://developer.apple.com/documentation/mediaplayer/mpvolumeview

This is the paragraph that I can't quite understand:

"Use this class by embedding an instance of it in your view hierarchy. The following code snippet assumes you’ve placed an instance of the UIView class on a view using Interface Builder, sizing and positioning it as desired to contain the volume view. Point to the UIView instance with an outlet variable—named, in the case of this example, mpVolumeViewParentView. You’d typically place code like that shown in Listing 1 in your viewDidLoad method."

Screenshots: enter image description here

I think I need the volumeView in the View class of my Main.storyboard enter image description here

Code that I'm then using to add the volumeView :

//  ViewController.swift


 Import UIKit
 import AVFoundation
 import MediaPlayer
 //import SwiftUI


 let rect = CGRect(x: 10, y: 10, width: 100, height: 100)

 let myView = UIView(frame: rect)


class ViewController: UIViewController, AVAudioRecorderDelegate, UITableViewDelegate, UITableViewDataSource{

//let wrapperView = UIView(frame: CGRect(x: 30, y: 200, width: 300, height: 20))

var recordingSession:AVAudioSession!
var audioRecorder:AVAudioRecorder!
var numberOfRecords:Int = 0
var audioPlayer = AVAudioPlayer()

@IBOutlet weak var buttonLabel: UIButton!

@IBOutlet weak var myTableview: UITableView!

@IBOutlet weak var airPlayView: UIView!




override func viewDidLoad() {
    super.viewDidLoad()

    myView.backgroundColor = UIColor.black
    let volumeView = MPVolumeView(frame: myView.bounds)
    myView.addSubview(volumeView)
    

I am developing on IOS 9.3.5 on Xcode 8.1.

0

There are 0 best solutions below