2015-05-15 5 views
11

आईओएस पर Spotify एक बहुत ही रोचक नियंत्रण केंद्र एकीकरण है। नीचे हैमबर्गर बटन पर ध्यान दें।Spotify आईओएस पर मीडिया प्लेबैक नियंत्रण को कैसे अनुकूलित करता है?

Hamburger

एक ही बात लॉक स्क्रीन पर है!

lock screen

वे उन कैसे करते हैं? क्या MPMediaCenter या कुछ में कोई एपीआई है?

उत्तर

15

हाँ, वहाँ निर्देश remote control events के बारे में सेब डॉक्स में पाया को देखते हुए कि

के लिए एक API आप दो वर्गों MPRemoteCommand और MPRemoteCommandCenter प्रकाश डाला मिलता है। MPRemoteCommandCenter देखकर आपको दिखाएगा कि likeCommand या dislikeCommand जैसे कई आदेश हैं, आप हैंडलर जोड़ सकते हैं। उन आदेशों पर हैंडलर जोड़ना उन्हें नियंत्रण केंद्र में प्रदर्शित मधुमक्खी का कारण बनता है।

- (void)showCustomizedControlCenter { 
    /* basic audio initialization */ 
    NSString *soundFilePath = [NSString stringWithFormat:@"%@/test.mp3", [[NSBundle mainBundle] resourcePath]]; 
    NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath]; 

    self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil]; 
    self.player.numberOfLoops = -1; 
    [self.player play]; 

    /* registering as global audio playback */ 
    [[AVAudioSession sharedInstance] setActive:YES error:nil]; 
    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil]; 

    /* the cool control center registration */ 
    MPRemoteCommandCenter *commandCenter = [MPRemoteCommandCenter sharedCommandCenter]; 
    [commandCenter.playCommand addTargetWithHandler:^MPRemoteCommandHandlerStatus(MPRemoteCommandEvent *event) { 
     return MPRemoteCommandHandlerStatusSuccess; 
    }]; 
    [commandCenter.dislikeCommand addTargetWithHandler:^MPRemoteCommandHandlerStatus(MPRemoteCommandEvent *event) { 
     return MPRemoteCommandHandlerStatusSuccess; 
    }]; 
    [commandCenter.likeCommand addTargetWithHandler:^MPRemoteCommandHandlerStatus(MPRemoteCommandEvent *event) { 
     return MPRemoteCommandHandlerStatusSuccess; 
    }]; 
    [commandCenter.nextTrackCommand addTargetWithHandler:^MPRemoteCommandHandlerStatus(MPRemoteCommandEvent *event) { 
     return MPRemoteCommandHandlerStatusSuccess; 
    }]; 

    /* setting the track title, album title and button texts to match the screenshot */ 
    commandCenter.likeCommand.localizedTitle = @"Thumb Up"; 
    commandCenter.dislikeCommand.localizedTitle = @"Thumb down"; 

    MPNowPlayingInfoCenter* info = [MPNowPlayingInfoCenter defaultCenter]; 
    NSMutableDictionary* newInfo = [NSMutableDictionary dictionary]; 

    [newInfo setObject:@"Mixtape" forKey:MPMediaItemPropertyTitle]; 
    [newInfo setObject:@"Jamie Cullum" forKey:MPMediaItemPropertyArtist]; 

    info.nowPlayingInfo = newInfo; 
} 

इसके अलावा करने के लिए AVFoundation जोड़ने कोड आप

  • करने की जरूरत है लिखने के लिए:

    नीचे काफी ठीक उसी परिणाम प्राप्त करने के लिए कुछ सब-इन-वन कोड अपने स्क्रीनशॉट पर दिखाया है आपकी परियोजना

  • #import <AVFoundation/AVFoundation.h> और #import <MediaPlayer/MediaPlayer.h>
  • पृष्ठभूमि मोडसक्रिय करें ऐप सेटिंग्स में।

enter image description here enter image description here

संबंधित मुद्दे