Forum Xamarin.iOS

Has anyone gotten AVRoutePickerView and AVRouteDetector to work on Xamarin.iOS?

Gmoney494Gmoney494 USMember ✭✭

So my app uses MPVolumeView to help display the AirPlay workflow on the video player. I know that it has been deprecated in favor of AVRoutePickerView. I finally got around to doing the work and while there is little to no documentation or articles on the migration, i did find this little gem: https://jeroenscode.com/avroutepickerview-replaces-mpvolumeview/.

The article denotes that you also have to use AVRouteDetector to get some of the extra functionality (device detection and what not) working. Now i got the AVRoutePickerView to work and initialize in my code. However when i try to create an AVRouteDetector, I cannot as the default constructor doesnt work (var detector = new AVRouteDetector(), i checked the bindings and it seems the default constructor is disabled). So my question is, has any gotten AVRouteDetector to work? And in conjuction AVRoutePickerView? Since they are both required to get everything working.

Answers

  • ColeXColeX Member, Xamarin Team Xamurai

    AVRouteDetector is used in notification , we do not need to initialize it .

    Sample code

      NSNotificationCenter.DefaultCenter.AddObserver(AVRouteDetector.MultipleRoutesDetectedDidChange, (NSNotification noti)=>
                {
                    AVRouteDetector avRouteDetector = (AVRouteDetector)noti.Object;
                    if (avRouteDetector.MultipleRoutesDetected)
                    {
    
                    }
                    else
                    {
    
                    }
    
                },null);
    
  • Gmoney494Gmoney494 USMember ✭✭

    @ColeX said:
    AVRouteDetector is used in notification , we do not need to initialize it .

    Sample code

      NSNotificationCenter.DefaultCenter.AddObserver(AVRouteDetector.MultipleRoutesDetectedDidChange, (NSNotification noti)=>
                {
                    AVRouteDetector avRouteDetector = (AVRouteDetector)noti.Object;
                    if (avRouteDetector.MultipleRoutesDetected)
                    {
    
                    }
                    else
                    {
    
                    }
    
                },null);
    

    @ColeX So i tried that and didnt work for me. According to this SO post, you need to initialize the AVRouteDetector. There is a native app i was looking at that also runs AVRoutePickerView and they initialize AVRouteDetector and maintain a reference to it, to then set a flag: routeDetector.isRouteDetectionEnabled = true.

  • ColeXColeX Member, Xamarin Team Xamurai

    I didn't find the docs/tutorial about how to use AVRouteDetector .

    Check the image , maybe helpful .

  • Gmoney494Gmoney494 USMember ✭✭

    @ColeX said:
    I didn't find the docs/tutorial about how to use AVRouteDetector .

    Check the image , maybe helpful .

    Yea ive tried to instantiate it and i couldnt. Nor could i find any documentation or tutorials with code examples in Xamarin.iOS like you noted. I see it works regularly in Xcode (Swift or Objective-C) but not sure if the Xamarin.iOS binding of it is working.

  • Gmoney494Gmoney494 USMember ✭✭
    edited November 2020

    @ColeX i opened this ticket in GitHub: https://github.com/xamarin/xamarin-macios/issues/10139

    Thanks for your help.

Sign In or Register to comment.