【问题标题】:MPNowPlayingInfoCenter AVPlayerMPNowPlayingInfoCenter AVPlayer
【发布时间】:2015-08-31 10:50:27
【问题描述】:

我正在开发一个应用程序。我正在使用 AVPlayer 播放音频。我想通过控制屏幕按钮控制音频。我不知道如何注册远程事件。

【问题讨论】:

标签: ios xamarin


【解决方案1】:

我的示例实现了这个功能: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();

【讨论】:

    猜你喜欢
    • 2014-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-17
    • 1970-01-01
    • 2020-07-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多