beginReceivingRemoteControlEvents not triggering events for Apple Music

前端 未结 1 2032
温柔的废话
温柔的废话 2021-02-15 17:29

I am playing Apple Music from my application , the apple music player code is as -

-(void) submitAppleMusicTrackWithProductID: (NSString *) productID // productI         


        
1条回答
  •  灰色年华
    2021-02-15 18:10

    Instead of using -(void)remoteControlReceivedWithEvent:(UIEvent *)event to track for the controls, use MPRemoteCommandCenter adding targets to each one of the controls:

    Note: It's important to enable the controls before assigning a target.

    [MPRemoteCommandCenter sharedCommandCenter].playCommand.enabled = YES;
    [[MPRemoteCommandCenter sharedCommandCenter].playCommand addTarget:self action:@selector(remotePlay)];
    
    [MPRemoteCommandCenter sharedCommandCenter].pauseCommand.enabled = YES;
    [[MPRemoteCommandCenter sharedCommandCenter].pauseCommand addTarget:self action:@selector(remoteStop)];
    
    [MPRemoteCommandCenter sharedCommandCenter].previousTrackCommand.enabled = YES;
    [[MPRemoteCommandCenter sharedCommandCenter].previousTrackCommand addTarget:self action:@selector(loadPreviousSong)];
    
    [MPRemoteCommandCenter sharedCommandCenter].nextTrackCommand.enabled = YES;
    [[MPRemoteCommandCenter sharedCommandCenter].nextTrackCommand addTarget:self action:@selector(loadNextSong)];
    

    Selectors:

    -(void) remotePlay {
        [APP_DELEGATE PlayPauseMusic:nil];
    }
    -(void) remoteStop {
        [APP_DELEGATE PlayPauseMusic:nil];
    }
    -(void) loadNextSong {
        [APP_DELEGATE next:nil];
    }
    -(void) loadPreviousSong {
        [APP_DELEGATE previous:nil];
    }
    

    0 讨论(0)
提交回复
热议问题