iOS app如何在進(jìn)入背景模式的時(shí)候依然播放音樂
就像douban電臺(tái)那樣, 不但在退出程序以后依然有音樂播放, 就連雙擊home按鈕以后左邊的音樂控制欄都變成douban電臺(tái)的圖標(biāo)了, 請(qǐng)問(wèn)這是如何做到的?
小伙看你根骨奇佳,潛力無(wú)限,來(lái)學(xué)PHP伐。
1. Background playback is done by adding Info.plist
to UIBackgroundModes
in audio
for reference https://developer.apple.com/library/i...
2. "Even after double-clicking the home button, the music control bar on the left turns into the icon of Douban Radio." This is to register an object in your own program as a responder to the corresponding remote control message. When the user clicks prev, next, play/pause in the control bar, the program will receive the corresponding message. When receiving the message, you must control the playback accordingly.
Register the responder in the view controller:
- (void) viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; [self becomeFirstResponder]; } - (void) viewWillDisappear:(BOOL)animated { [[UIApplication sharedApplication] endReceivingRemoteControlEvents]; [self resignFirstResponder]; [super viewWillDisappear:animated]; } - (BOOL) canBecomeFirstResponder { return YES; }
At the same time, the view controller needs to implement:
- (void) remoteControlReceivedWithEvent: (UIEvent *) receivedEvent;
3. Making the control bar display a title is another matter. You need to call the media center interface in the program to set the title and cover. Referencehttp://stackoverflow.com/questions/10...
4. Getting the album cover and title from ID3 is the fourth thing. .