【问题标题】:Custom audio player controls on notification ios通知 ios 上的自定义音频播放器控件
【发布时间】:2018-04-29 05:19:10
【问题描述】:

如何实现音频播放器以从 url 流式传输音乐,但我不知道如何将媒体播放器控件放入通知中,如 gaana 和 saavn 应用程序。 一旦用户播放歌曲通知应显示在通知栏上,用户可以控制播放,暂停下一个,从通知部分倒回音频。

enter image description here

【问题讨论】:

标签: ios swift notifications swift4 audio-streaming


【解决方案1】:

简单,不需要第三方库

import MediaPleyer

并在遥控器上添加观察者 Like

MPRemoteCommandCenter.shared().pauseCommand.addTarget(self, action: #selector(self.onPauseRemoteCommand(_:)))
MPRemoteCommandCenter.shared().playCommand.addTarget(self, action: #selector(self.onPlayRemoteCommand(_:)))

【讨论】:

  • 感谢@AlokMaurya
  • @SPatel 一旦从通知面板按下暂停按钮,通知面板就会消失。如何保留它。
  • @SPatel 还有一件事。我有一个音乐应用程序,它有多个屏幕,如收藏夹、下载、家庭、音乐商店。根据我的理解和实现,只需添加这两行,就会触发通知面板,无论您从哪里播放音乐,它都会在暂停命令上触发相同的功能,因此应用程序崩溃,因为我需要更新与任何屏幕相关的 UI我在。我该如何操作它,所以在每个屏幕上都会调用独特的函数来处理各个屏幕的 UI。
  • @UsamabinAttique 只需创建公共对象前“PlayerManager”。并为 remoteCommandCenter 注册该对象
  • @UsamabinAttique 通知面板在您设置 MPNowPlayingInfoCenter.default().nowPlayingInfo = nil 后消失。请确保您没有设置暂停事件。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-22
  • 2018-03-23
相关资源
最近更新 更多