Background Sound - Lock Screen Image

There is a way to add an image to the lock screen for Background audio, as well as set the name of the track and artist. It was also mentioned in the 2011 WWDC video, but nothing special to leave. I looked everywhere in the docs and can't find it. I know that this is only iOS5, and the new version of Spotify has this feature. Does anyone know where they can point me in the right direction?

Thanks Matthew

+6
source share
3 answers

Here is the answer I found for you:

(1) You must handle remote control events. You may not be playing the application now if you do not. (See AudioMixer Sample (MixerHost) .)

(2) Set the current information:

MPNowPlayingInfoCenter *infoCenter = [MPNowPlayingInfoCenter defaultCenter]; infoCenter.nowPlayingInfo = [NSDictionary dictionaryWithObjectsAndKeys:@"my title", MPMediaItemPropertyTitle, @"my artist", MPMediaItemPropertyArtist, nil]; 

It doesn’t depend on which API you use to play audio or video.

+10
source

as Michaels answer above, just add

 @{MPMediaItemPropertyArtwork: [[MPMediaItemArtwork alloc] initWithImage:[UIImage ...]]} 

in nowPlayingInfo dict

full options of available keys ...

 // MPMediaItemPropertyAlbumTitle // MPMediaItemPropertyAlbumTrackCount // MPMediaItemPropertyAlbumTrackNumber // MPMediaItemPropertyArtist // MPMediaItemPropertyArtwork // MPMediaItemPropertyComposer // MPMediaItemPropertyDiscCount // MPMediaItemPropertyDiscNumber // MPMediaItemPropertyGenre // MPMediaItemPropertyPersistentID // MPMediaItemPropertyPlaybackDuration // MPMediaItemPropertyTitle 
+3
source

To make management work ...

 - (BOOL)canBecomeFirstResponder { return YES; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; [self becomeFirstResponder]; } - (void)viewWillDisappear:(BOOL)animated { [[UIApplication sharedApplication] endReceivingRemoteControlEvents]; [self resignFirstResponder]; [super viewWillDisappear:animated]; } - (void)remoteControlReceivedWithEvent:(UIEvent *)receivedEvent { if (receivedEvent.type == UIEventTypeRemoteControl) { switch (receivedEvent.subtype) { case UIEventSubtypeRemoteControlPlay: [player play]; break; case UIEventSubtypeRemoteControlPause: [player pause]; break; case UIEventSubtypeRemoteControlTogglePlayPause: if (player.playbackState == MPMoviePlaybackStatePlaying) { [player pause]; } else { [player play]; } break; default: break; } } } 

It only works on a real iOS device, not a simulator

+1
source

Source: https://habr.com/ru/post/904037/


All Articles