有没有一种公开的方式,迫使MPNowPlayingInfoCenter显示播客的控制? [英] Is there a public way to force MPNowPlayingInfoCenter to show podcast controls?

查看:1789
本文介绍了有没有一种公开的方式,迫使MPNowPlayingInfoCenter显示播客的控制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想控制中心(通过MPNowPlayingInfoCenter),以显示前进15秒/后退15秒控制,苹果展示了播客,像这样:

I would like Control Center (via MPNowPlayingInfoCenter) to show the forward 15 seconds / back 15 seconds controls that Apple shows with podcasts, like so:

在完全缺乏文档告诉我,有没有的明显的方式做到这一点,但有没有人在那里发现的不明显的方式,迫使该而不诉诸一个私有方法?

The utter lack of documentation tells me that there's no obvious way to do this, but has anyone out there found any non-obvious way to force this without resorting to a private method?

我已经得到了我的前进/后退按钮可以设置适当提前处理,我只是想用更合适的UI。任何帮助将大大AP preciated。

I've already got my handling for the forward/back button set up to advance appropriately, I'd just like to use the more appropriate UI. Any help would be greatly appreciated.

推荐答案

行,所以我对我的手一点时间,所以我跟着面包屑。...
这是我发现的。

OK so I had a bit of time on my hands and so I followed the breadcrumb.… This is what I found.

包含的MediaPlayer的框架,并得到RemoteCommandCenter的保持:

Include the MediaPlayer framework and get hold of the RemoteCommandCenter:

MPRemoteCommandCenter *rcc = [MPRemoteCommandCenter sharedCommandCenter];

那么,如果你想设置跳过控件每雷雨你可以做到以下几点:

then if you wanted to set the skip controls as per Overcast you can do the following:

MPSkipIntervalCommand *skipBackwardIntervalCommand = [rcc skipBackwardCommand];
[skipBackwardIntervalCommand setEnabled:YES];
[skipBackwardIntervalCommand addTarget:self action:@selector(skipBackwardEvent:)];
skipBackwardIntervalCommand.preferredIntervals = @[@(42)];  // Set your own interval

MPSkipIntervalCommand *skipForwardIntervalCommand = [rcc skipForwardCommand];
skipForwardIntervalCommand.preferredIntervals = @[@(42)];  // Max 99
[skipForwardIntervalCommand setEnabled:YES];
[skipForwardIntervalCommand addTarget:self action:@selector(skipForwardEvent:)];

和在事件处理程序做你需要做的间隔跳过什么:

and in the event handlers do what you need to do to skip by the interval:

-(void)skipBackwardEvent: (MPSkipIntervalCommandEvent *)skipEvent
{
    NSLog(@"Skip backward by %f", skipEvent.interval);
}

-(void)skipForwardEvent: (MPSkipIntervalCommandEvent *)skipEvent
{
    NSLog(@"Skip forward by %f", skipEvent.interval);
}

注:preferredIntervals属性是一个NSArray,但我还没有想出如何间隔额外可通过指挥中心,除非你自己做一些与此可利用

Note: The preferredIntervals property is an NSArray but I haven’t figured out how extra intervals can be utilised by the command center unless you do something with this yourself.

需要注意的事项,我已经发现迄今。当你这样做,你正在服用的所有控件控制,默认的播放和暂停按钮不会显示,除非你为他们做相同的:

Things to note that I’ve found so far. When you do this you are taking control of all the controls so the default play and pause buttons won't show unless you do the same for them:

MPRemoteCommand *pauseCommand = [rcc pauseCommand];
[pauseCommand setEnabled:YES];
[pauseCommand addTarget:self action:@selector(playOrPauseEvent:)];
//    
MPRemoteCommand *playCommand = [rcc playCommand];
[playCommand setEnabled:YES];
[playCommand addTarget:self action:@selector(playOrPauseEvent:)];

(也有定义的togglePlayPauseCommand但我便无法得到这个从指挥中心火 - 它确实火从耳机虽然)

(there is also a togglePlayPauseCommand defined but I could’t get this to fire from the Command Centre - it does fire from headphones though.)

其他的发现:
这些按钮是左固定位置/中/右,所以你不能有(例如)previousTrack和skipBackward因为它们都占据了左侧位置。

Other discoveries: The buttons are in fixed positions left / middle / right so you cant have (for example) a previousTrack and a skipBackward as they both occupy the left position.

有seekForward / seekBackward需要一个prevTrack和nextTrack指令被触发命令。当您设置既然后一个水龙头下一触发/ previous和preSS和保持触发开始寻求,当你抬起手指最终所追求的。

There are seekForward / seekBackward commands that need a prevTrack and nextTrack command to be triggered. When you set up both then a single tap triggers next / previous and a press and hold triggers a begin seek and an end seek when you lift your finger.

    // Doesn’t show unless prevTrack is enabled
    MPRemoteCommand *seekBackwardCommand = [rcc seekBackwardCommand];
    [seekBackwardCommand setEnabled:YES];
    [seekBackwardCommand addTarget:self action:@selector(seekEvent:)];

    // Doesn’t show unless nextTrack is enabled
    MPRemoteCommand *seekForwardCommand = [rcc seekForwardCommand];
    [seekForwardCommand setEnabled:YES];
    [seekForwardCommand addTarget:self action:@selector(seekEvent:)];

-(void) seekEvent: (MPSeekCommandEvent *) seekEvent
{
    if (seekEvent.type == MPSeekCommandEventTypeBeginSeeking) {
        NSLog(@"Begin Seeking");
    }
    if (seekEvent.type == MPSeekCommandEventTypeEndSeeking) {
        NSLog(@"End Seeking");
    }
}

还有,我还没有见过一个反馈机制(左占据位置)

There is also a feedback mechanism that I haven’t seen before (occupies left position)

    MPFeedbackCommand *likeCommand = [rcc likeCommand];
    [likeCommand setEnabled:YES];
    [likeCommand setLocalizedTitle:@"I love it"];  // can leave this out for default
    [likeCommand addTarget:self action:@selector(likeEvent:)];

    MPFeedbackCommand *dislikeCommand = [rcc dislikeCommand];
    [dislikeCommand setEnabled:YES];
    [dislikeCommand setActive:YES];
    [dislikeCommand setLocalizedTitle:@"I hate it"]; // can leave this out for default
    [dislikeCommand addTarget:self action:@selector(dislikeEvent:)];

    BOOL userPreviouslyIndicatedThatTheyDislikedThisItemAndIStoredThat = YES;

    if (userPreviouslyIndicatedThatTheyDislikedThisItemAndIStoredThat) {
        [dislikeCommand setActive:YES];
    }

    MPFeedbackCommand *bookmarkCommand = [rcc bookmarkCommand];
    [bookmarkCommand setEnabled:YES];
    [bookmarkCommand addTarget:self action:@selector(bookmarkEvent:)];

// Feedback events also have a "negative" property but Command Center always returns not negative
-(void)dislikeEvent: (MPFeedbackCommandEvent *)feedbackEvent
{
    NSLog(@"Mark the item disliked");
}

-(void)likeEvent: (MPFeedbackCommandEvent *)feedbackEvent
{
    NSLog(@"Mark the item liked");
}

-(void)bookmarkEvent: (MPFeedbackCommandEvent *)feedbackEvent
{
    NSLog(@"Bookmark the item or playback position");
}

这显示了三个单杠,并带来了一个警报表 - 你可以通过设置活动属性单独突出这些

This displays three horizontal bars and brings up an alert sheet - you can highlight these individually by setting the active property.

还有一个等级命令定义 - 但我不能得到这个在指挥中心显示

There is also a rating command defined - but I couldn't get this to show in the Command Center

//    MPRatingCommand *ratingCommand = [rcc ratingCommand];
//    [ratingCommand setEnabled:YES];
//    [ratingCommand setMinimumRating:0.0];
//    [ratingCommand setMaximumRating:5.0];
//    [ratingCommand addTarget:self action:@selector(ratingEvent:)];

和一个播放速率改变命令 - 但同样不能得到这个指挥中心显示

and a playback rate change command - but again couldn’t get this to show in Command Center

//    MPChangePlaybackRateCommand *playBackRateCommand = [rcc changePlaybackRateCommand];
//    [playBackRateCommand setEnabled:YES];
//    [playBackRateCommand setSupportedPlaybackRates:@[@(1),@(1.5),@(2)]];
//    [playBackRateCommand addTarget:self action:@selector(remoteControlReceivedWithEvent:)];

还有一个基于块的目标作用机制,如果你preFER

There is also a block-based target action mechanism if you prefer

// @property (strong, nonatomic) id likeHandler;
    self.likeHandler = [likeCommand addTargetWithHandler:^MPRemoteCommandHandlerStatus(MPRemoteCommandEvent *event) {
        NSLog(@"They like it");
        return MPRemoteCommandHandlerStatusSuccess;  // or fail or no such content
    }];

最后一点需要注意的:如果您已经注册获得通过[UIApplication的sharedApplication] beginReceivingRemoteControlEvents]远程事件;那么其中的某些命令也触发事件 - (无效)remoteControlReceivedWithEvent:(*的UIEvent)receivedEvent处理程序。这些虽与类型UIEventTypeRemoteControl和子类型区分事件UIEvents。你不能混用,并与该方法M. premoteCommandEvents匹配这些。有线索在于M premoteCommandEvents会在某个时候取代UIEvents。

One final point to be aware of: If you have registered to receive remote events via [[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; then some of these commands also trigger events in the - (void)remoteControlReceivedWithEvent:(UIEvent *)receivedEvent handler. These are UIEvents though with type UIEventTypeRemoteControl and a subtype to distinguish the event. You can't mix and match these with MPRemoteCommandEvents in this method. There are hints that MPRemoteCommandEvents will replace the UIEvents at some point.

所有这一切都基于试验和错误,以便随时纠正。

All of this based on trial and error so feel free to correct.

加雷思

这篇关于有没有一种公开的方式,迫使MPNowPlayingInfoCenter显示播客的控制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆