如何解决MPRemoteCommandCenter播放/暂停命令无法正确更新
我已经设置了播放/暂停按钮,并且为每个按钮都添加了目标事件,但是当我在模拟器中单击按钮时,它总是调用播放按钮的目标事件,并且按钮的图像从播放到暂停都没有正确更新,反之亦然。有人对此有想法吗?
注意:要播放/暂停音频,我使用了Plugin.MediaManager.Forms nuget(版本0.9.7)
[Export("playableContentManager:initiatePlaybackOfContentItemAtIndexPath:completionHandler:")]
public override void InitiatePlaybackOfContentItem(MPPlayableContentManager contentManager,NSIndexPath indexPath,Action<NSError> completionHandler)
{
dispatchQueue.MainQueue.dispatchAsync(() =>
{
UIApplication.SharedApplication.EndReceivingRemoteControlEvents();
UIApplication.SharedApplication.BeginReceivingRemoteControlEvents();
var song = CarPlaylist[indexPath.Section].episodes[indexPath.Row];
var NowPlayingInfoCenter = MPNowPlayingInfoCenter.DefaultCenter;
MPNowPlayingInfo playingInfo = new MPNowPlayingInfo();
playingInfo.Title = song.Title;
playingInfo.Artist = song.Editor;
playingInfo.PlaybackDuration = song.Duration.TotalSeconds; //provide time in seconds
playingInfo.MediaType = MPNowPlayingInfoMediaType.Audio;
playingInfo.Artwork = new MPMediaItemArtwork(image: ExtractArtWork.UIImageFromUrl(song.ArtWork));
playingInfo.AssetUrl = new NSUrl(song.FileUrl.AbsolutePath);
playingInfo.PlaybackRate = song.IsPlaying ? 1.0 : 0.0;
NowPlayingInfoCenter.NowPlaying = playingInfo;
var currentPlayItemId = episode.podcastId.ToString();
string[] identifier = new string[1];
identifier[0] = currentPlayItemId;
contentManager = MPPlayableContentManager.Shared;
contentManager.NowPlayingIdentifiers = identifier;
contentManager.DataSource = new AppDelegateDataSource(CarPlaylist);
var commandCenter = MPRemoteCommandCenter.Shared;
commandCenter.PlayCommand.Enabled = true;
commandCenter.PauseCommand.Enabled = true;
commandCenter.PlayCommand.AddTarget(PlayButton);
commandCenter.PauseCommand.AddTarget(PauseButton);
completionHandler(null);
UIApplication.SharedApplication.EndReceivingRemoteControlEvents();
UIApplication.SharedApplication.BeginReceivingRemoteControlEvents();
});
}
public MPRemoteCommandHandlerStatus PlayButton(MPRemoteCommandEvent commandEvent)
{
//Logic to update app UI to play mode and play audio
return MPRemoteCommandHandlerStatus.Success;
}
public MPRemoteCommandHandlerStatus PauseButton(MPRemoteCommandEvent commandEvent)
{
//Logic to update app UI to pause mode and pause audio
return MPRemoteCommandHandlerStatus.Success;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。