0

I am working on a app. I am using AVPlayer for audio. I want to control audio from control screen buttons. I don't know how to register for remote events.

serenesat
  • 4,611
  • 10
  • 37
  • 53
Neha Gupta
  • 291
  • 2
  • 18
  • 2
    What did you try so far? Can you provide any code to start with? Did you read [this tutorial](http://code.tutsplus.com/tutorials/ios-sdk_background-audio--mobile-6833) already? – user1438038 Aug 31 '15 at 11:10
  • Also check the list here to make sure you have satisfied all the requirements http://stackoverflow.com/a/30085578/1107580 – Iain Smith Aug 31 '15 at 12:52

1 Answers1

-1

My example implements this functionality: https://github.com/martijn00/XamarinMediaManager/blob/master/MediaManager/MediaManager.Plugin.iOSUnified/MediaManagerImplementation.cs

The code you should use is:

          player.ReplaceCurrentItemWithPlayerItem(streamingItem);
          streamingItem.AddObserver(this, new NSString("status"), NSKeyValueObservingOptions.New, player.Handle);
          streamingItem.AddObserver(this, new NSString("loadedTimeRanges"), NSKeyValueObservingOptions.Initial | NSKeyValueObservingOptions.New, player.Handle);

          player.CurrentItem.SeekingWaitsForVideoCompositionRendering = true;
          player.CurrentItem.AddObserver(this, (NSString)"status", NSKeyValueObservingOptions.New |
              NSKeyValueObservingOptions.Initial, StatusObservationContext.Handle);

          NSNotificationCenter.DefaultCenter.AddObserver(AVPlayerItem.DidPlayToEndTimeNotification, async (notification) =>
          {
              await PlayNext();
          }, player.CurrentItem);

          player.Play();
Martijn00
  • 3,569
  • 3
  • 22
  • 39