2015-08-31 60 views
0

我正在開發一個應用程序。我正在使用AVPlayer進行音頻播放。我想控制來自控制屏幕按鈕的音頻。我不知道如何註冊遠程事件。MPNowPlayingInfoCenter AVPlayer

+2

那你試試這麼遠嗎?你能提供任何代碼開始?您是否已閱讀[本教程](http://code.tutsplus.com/tutorials/ios-sdk_background-audio--mobile-6833)? – user1438038

+0

另請查看此處的列表以確保您已滿足所有要求http://stackoverflow.com/a/30085578/1107580 –

回答

0

我的例子實現了這個功能:https://github.com/martijn00/XamarinMediaManager/blob/master/MediaManager/MediaManager.Plugin.iOSUnified/MediaManagerImplementation.cs

你應該使用的代碼是:

  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();