0

I've implemented the volumeView class onto my app so that I can pick and output my audio via airplay however the button for this is not showing.

I don't get any compiler errors and after reading Airplay Button is not showing in Player Controls with AVPlayer I can't work out what I'm doing differently.

The code:

 override func viewDidLoad() {
    super.viewDidLoad()
    
    let volumeView = MPVolumeView(frame: myView.bounds);
    self.view.addSubview(volumeView);
    
    volumeView.showsRouteButton = true;
    self.view.backgroundColor = UIColor.red;
    volumeView.center = CGPoint(x:380, y:150)

Any advice is much appreciated.

Greg
  • 476
  • 9
  • 23
  • Why do you set the volume view's frame and position in that strange way? It makes no sense. – matt Oct 10 '21 at 22:13
  • Bit of an IOS noob if I'm honest and just ended up with this after a series of trial and error. Can you suggest a more sensible alternative - I want the view in the top 25% of the screen, with the view centered. I did hace `volumeView.center = self.view.center` but this put it in the center of the whole screen. – Greg Oct 11 '21 at 07:50
  • My main query is about why the route button is not showing - any ideas as to why this might be? – Greg Oct 11 '21 at 07:51

1 Answers1

0

I'm going to guess that this isn't supposed to work any more. On my device, if you change to an AirPlay device using the control center, the MPVolumeView disappears completely.

So I would advise against use of MPVolumeView, except perhaps for the simplest cases. It is extremely old technology and hasn't worked as advertised for years. Properties like showsRouteButton and areWirelessRoutesAvailable were deprecated years ago.

The user can change routes using the control center, or you can present an AVRoutePickerView; and you can detect route changes with AVRouteDetector. So you really don't need this feature of MPVolumeView anyway.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • I don't think I can use AVRoutePickerView as I can only go as high as 10.1 on my VM of xcode. I just want the base functionality to switch the media to my Airplay server. Do you think It's possible with such an old device, or am i better off finding a more up to date vm? – Greg Oct 11 '21 at 17:54