Reputation:
I use this code to show information about track and to using play/pause button.
-(void)info
{
UIImage *image = [UIImage imageNamed:@"image.png"];
NSInteger highScore = [[[NSUserDefaults standardUserDefaults] objectForKey:@"int"] intValue];
MPMediaItemArtwork *albumArtwork = [[MPMediaItemArtwork alloc] initWithImage:image];
MPNowPlayingInfoCenter* mpic = [MPNowPlayingInfoCenter defaultCenter];
mpic.nowPlayingInfo = @{MPMediaItemPropertyArtist: @"1",
MPMediaItemPropertyTitle:[NSString stringWithFormat:@"1 %ld",(long)highScore],
MPMediaItemPropertyArtwork:albumArtwork,
MPMediaItemPropertyAlbumTitle: @"1",
MPNowPlayingInfoPropertyElapsedPlaybackTime:[NSNumber numberWithFloat: [self.audioPlayer getCurrentAudioTime]],
MPMediaItemPropertyPlaybackDuration : [NSNumber numberWithFloat:[self.audioPlayer getAudioDuration]]};
}
- (void)remoteControlReceivedWithEvent:(UIEvent *)receivedEvent {
if (receivedEvent.type == UIEventTypeRemoteControl) {
switch (receivedEvent.subtype) {
case UIEventSubtypeRemoteControlPreviousTrack:
NSLog(@"prev");
break;
case UIEventSubtypeRemoteControlNextTrack:
NSLog(@"next");
break;
case UIEventSubtypeRemoteControlPlay:
[_audioPlayer playAudio];
break;
case UIEventSubtypeRemoteControlPause:
[_audioPlayer pauseAudio];
break;
default:
break;
}
}
}
I want to use buttons for rewind(like below image) like in Apple Music app.
If I tap on button audioPlayer move to the next track. If I long tap on button track is rewind. How to do it?
Upvotes: 3
Views: 201
Reputation: 3089
Add this 2 lines in "- (void)viewDidLoad"
[[AVAudioSession sharedInstance] setDelegate: self];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
Upvotes: 1