2013-10-25 7 views
6

आईओएस 7 संगीत ऐप के साथ एक गाना बजाने पर उपयोगकर्ता लॉक स्क्रीन/नियंत्रण केंद्र में गीत स्थिति बदलने के लिए स्लाइडर का उपयोग कर सकता है। स्लाइडर सक्रिय है:लॉक स्क्रीन/नियंत्रण केंद्र पर ट्रैक स्थिति कैसे बदलें?

enter image description here

लेकिन जब मेरी एप्लिकेशन को उपयोगकर्ता में संगीत बजाने यह नहीं कर सकते। स्लाइडर सक्रिय नहीं है:

enter image description here

मैं अपने ऐप में इन सुविधा कैसे सक्षम कर सकते हैं?

+0

आप कैसे खेल रहे हैं संगीत है? – WDUK

+0

@WDUK MPMoviePlayerController के माध्यम से –

+0

@NeimanAleksei आप गीत शीर्षक और गीत अवधि कैसे दिखाते हैं? – Desmond

उत्तर

9

आप iOS 9.1 और उच्चतर पर MPRemoteCommandCenter की मदद से ट्रैक स्थिति बदल सकते हैं - AppDelegate में निम्न विधि

- (void)remoteControlReceivedWithEvent:(UIEvent *)receivedEvent { 

if (receivedEvent.type == UIEventTypeRemoteControl) { 

    switch (receivedEvent.subtype) { 
     case UIEventSubtypeRemoteControlPause: 
      //pause code here 
      break; 

     case UIEventSubtypeRemoteControlPlay: 
      //play code here 
      break; 

     case UIEventSubtypeRemoteControlPreviousTrack: 
      // previous track code here 
      break; 

     case UIEventSubtypeRemoteControlNextTrack: 
      //next track code here 
      break; 

     default: 
      break; 
    } 
} 

} सेब डॉक्स से MPNowPlayingInfoCenter पर

अधिक जानकारी जोड़ें।

if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_9_0) { 
      MPRemoteCommandCenter *commandCenter = [MPRemoteCommandCenter sharedCommandCenter]; 
      [commandCenter.changePlaybackPositionCommand setEnabled:true]; 
      [commandCenter.changePlaybackPositionCommand addTarget:self action:@selector(changedThumbSliderOnLockScreen:)]; 
     } 

और विधि

- (MPRemoteCommandHandlerStatus)changedThumbSliderOnLockScreen:(MPChangePlaybackPositionCommandEvent *)event 
{ 
    // change position 
    [self setCurrentPlaybackTime:event.positionTime]; 
    // update MPNowPlayingInfoPropertyElapsedPlaybackTime 
    [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo]; 

    return MPRemoteCommandHandlerStatusSuccess; 
} 
3

मैं एक ही बात के लिए देख रहा था लेकिन मुझे नहीं लगता यह संभव है कि इस पोस्ट को देख:

How to enable audio scrubber in iOS Lock Screen control panel?

इसके अलावा Spotify और Soundcloud जैसे लोकप्रिय एप्लिकेशन इसका कार्यान्वित नहीं है।

यदि आप लॉक स्क्रीन पर वर्तमान संगीत दिखाने का कोई तरीका ढूंढ रहे हैं तो आपको निम्न कार्य करने की आवश्यकता है।

सबसे पहले जब आप एक नया ट्रैक अद्यतन NowPlayingInfo खेलने:

NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init]; 

    [songInfo setObject:trackTitle forKey:MPMediaItemPropertyTitle]; 
    [songInfo setObject:artistName forKey:MPMediaItemPropertyArtist]; 
    [songInfo setObject:duration forKey:MPMediaItemPropertyPlaybackDuration]; 
    [songInfo setObject:releaseDate forKey:MPMediaItemPropertyReleaseDate]; 
    [songInfo setValue:playbackRate forKey:MPNowPlayingInfoPropertyPlaybackRate]; 
    [songInfo setObject:elapsedTime forKey:MPNowPlayingInfoPropertyElapsedPlaybackTime]; 
    [songInfo setObject:albumArtImage forKey:MPMediaItemPropertyArtwork]; 
    [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo]; 

लॉकस्क्रीन से घटनाओं को संभालने के लिए, आप रिमोट कंट्रोल से घटनाओं प्राप्त करना शुरू करने के लिए अपने एप्लिकेशन को बताने के लिए पहली जरूरत है। मैं निम्नलिखित कोड

// Turn on remote control event delivery 
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; 

इसके बाद आप पर कब्जा कर लिया ईवेंट प्रबंधित करने के remoteControlReceivedWithEvent विधि लागू करने की आवश्यकता का उपयोग कर मेरे AppDelegate के आवेदन didFinishLaunchingWithOptions में करते हैं। >https://developer.apple.com/library/ios/documentation/mediaplayer/reference/MPNowPlayingInfoCenter_Class

0

swift4 आप iOS 9.1 और उच्चतर पर MPRemoteCommandCenter की मदद से ट्रैक स्थिति बदल सकते हैं।

let commandCenter = MPRemoteCommandCenter.shared() 
commandCenter.changePlaybackPositionCommand.isEnabled = true 
     commandCenter.changePlaybackPositionCommand.addTarget(self, action:#selector(changePlaybackPositionCommand(_:))) 

और विधि

@objc func changePlaybackPositionCommand(_ event:MPChangePlaybackPositionCommandEvent) -> MPRemoteCommandHandlerStatus{ 
let time = event.positionTime 
     //use time to update your track time 
     return MPRemoteCommandHandlerStatus.success; 
    } 

टिप्पणी आपको बस इतना करना है कि commandCenter में हर आदेश के लिए आप चाहते हैं अगर यह आपके एप्लिकेशन में सक्षम होने के लिए

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