2013-12-15 36 views
44

我想控制中心(通過MPNowPlayingInfoCenter),顯示15向前秒/分回15秒控制,蘋果顯示了播客,像這樣:有沒有一種公開的方式來強制MPNowPlayingInfoCenter顯示播客控件?

podcast controls

的極度缺乏文檔告訴我,有沒有顯而易見這樣做的方式,但有沒有人發現有任何非顯而易見的方式來強制這一點,而不訴諸私人方法?

我已經得到了對前進/後退按鈕設置的適當推進的處理,我只想使用更合適的用戶界面。任何幫助將不勝感激。

+0

控制中心似乎一成不變的,只要大多數的事情走。不僅應用程序開發人員不能編輯它,甚至用戶也不能編輯控制中心中的按鈕。蘋果不再分享一次。 – erdekhayser

+0

如果有辦法做到這一點,我相信其他10個獨立播客客戶端都會實現它。 – seanwolter

+0

是的,我有點希望在這裏。我會提供一個雷達。 – DesignatedNerd

回答

110

好吧,我有一點時間在我的手上,所以我跟着麪包屑...... 這就是我發現的。

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

MPRemoteCommandCenter *rcc = [MPRemoteCommandCenter sharedCommandCenter]; 

然後如果你想設置跳過控件每間多雲,你可以做到以下幾點:

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:)]; 

,並在事件處理程序做你需要做的事情以跳過間隔:

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

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

注意:preferredIntervals屬性是一個NSArray,但我還沒有弄清楚如何額外的間隔可以被指揮中心利用,除非你自己做這件事。

需要注意的是,我發現迄今爲止。當你這樣做,你正在服用的所有控件的控制,使默認播放和暫停按鈕不會顯示,除非你爲他們做同樣的:

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但我便無法儘管如此,從指揮中心發射它 - 它確實從耳機發射。)

其他發現: 按鈕位於左側/中間/右側的固定位置,因此您不能將(例如)previousTrack和skipBackward as他們都佔據左邊的位置。

有seekForward/seekBackward命令需要觸發prevTrack和nextTrack命令。當你設置兩個時,然後一個輕擊觸發下一個/上一個,按住時觸發一個開始搜索和一個結束搜索時,你舉手指。

// 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"); 
    } 
} 

還有,我以前從未見過的反饋機制(左佔據位置)

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"); 
} 

這顯示了三個單槓,並提出了警示片 - 您可以通過單獨突出這些設置活動屬性。

也有定義的等級命令 - 但我不能得到這個在指揮中心

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

和播放速率變化命令顯示 - 但同樣不能得到這個在命令show中心

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

還有,如果你喜歡一個基於塊的目標作用機制

// @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]註冊接收遠程事件;那麼這些命令中的一些還會觸發 - (void)remoteControlReceivedWithEvent:(UIEvent *)receivedEvent處理程序中的事件。儘管UIEvent類型是UIEventTypeRemoteControl和一個子類型,但它們都是UIEvents來區分事件。您不能在這種方法中將這些與MPRemoteCommandEvents進行混合和匹配。有跡象表明MPRemoteCommandEvents會在某些時候替換UIEvents。

所有這一切都基於試驗和錯誤,所以請隨時糾正。

加雷思

Screenshot of feedback command and skipforward

+0

是一個在「控制中心」中自動設置「倒回42秒」圖標,然後在實現'skipBackwardCommand.preferredIntervals = @ [@(42)];'?時,這就是這個問題的關鍵,圖標/控件。你可以發佈圖片嗎? – pkamb

+0

是的 - 現在添加了屏幕截圖 – Gareth

+1

感謝您的詳細解答! – DesignatedNerd

2

蘋果沒有文檔,因爲沒有辦法改變這一點。再次,蘋果保持最好的東西本身(Siri也想到了)。

越獄版本支持更改控制中心按鈕,我在this site上找到了這些按鈕。我有一種感覺,你想使用這個應用程序的實際 iOS 7,而不是一個越獄版本,所以這根本不幫你。

這些私有API太頻繁地妨礙開發好的應用程序。除非Apple給我們更多的自由來使用當前私有的API,否則你運氣不好。

+3

不幸的是,對於7.x,這是正確的答案。如果你像我一樣胡思亂想,我會鼓勵你提交一個雷達,詢問是否有權訪問這個功能。可能只是在一口井下大喊大叫,但他們似乎偶爾會看到它們。 https://bugreport.apple.com/ – DesignatedNerd

+1

@DesignatedNerd雷達提交。 – erdekhayser

2

Oooooooh。馬科·阿門特得到這個在清除工作,並且至少留給卡斯特羅傢伙導航條與this tweet

這是MPRemoteCommandCenter。儘管如此,祝文件順利。

Here's said documentation的人誰一直在關注此問題 - 我猜它與skipBackwardCommandskipForwardCommand做。我沒有時間仔細研究它,所以我會在這裏留下來,以防有人想捅它並給出更徹底的答案。

+0

這可能有助於找出一個代碼示例:https://developer.apple.com/library/ios/documentation/MediaPlayer/Reference/MPSkipIntervalCommand_Ref/Reference/Reference.html#//apple_ref/occ/cl/MPSkipIntervalCommand – erdekhayser

2

對於斯威夫特開發商

import MediaPlayer 

let rcc = MPRemoteCommandCenter.shared() 

let skipBackwardCommand = rcc.skipBackwardCommand 
skipBackwardCommand.isEnabled = true 
skipBackwardCommand.addTarget(handler: skipBackward) 
skipBackwardCommand.preferredIntervals = [42] 

let skipForwardCommand = rcc.skipForwardCommand 
skipForwardCommand.isEnabled = true 
skipForwardCommand.addTarget(handler: skipForward) 
skipForwardCommand.preferredIntervals = [42] 

func skipBackward(_ event: MPRemoteCommandEvent) -> MPRemoteCommandHandlerStatus { 
    guard let command = event.command as? MPSkipIntervalCommand else { 
     return .noSuchContent 
    } 

    let interval = command.preferredIntervals[0] 

    print(interval) //Output: 42 

    return .success 
} 

func skipForward(_ event: MPRemoteCommandEvent) -> MPRemoteCommandHandlerStatus { 
    guard let command = event.command as? MPSkipIntervalCommand else { 
     return .noSuchContent 
    } 

    let interval = command.preferredIntervals[0] 

    print(interval) //Output: 42 

    return .success 
} 

其他命令將是相似的,他們可以檢查here

相關問題