MPMusicPlayerController stops sending notifications

I have an MPMusicPlayerController that plays the entire iPod library, and I signed up for notifications when tracks change, etc. It all works right

When the end of the playlist is reached, MPMusicPlayerController sends the status notification change and stops. When I restart the player again, the music starts playing again, but MPMusicPlayerController no longer sends notifications when changing tracks, etc.

Thoughts?

+1
source share
2 answers

After a lot of experimenting, this is what solved my problem.

, , ""; "play" - "".

, , "", , , , reset - , , "stop" , "play" .

+3

-, MPMusicPlayerControllerPlaybackStateDidChangeNotification , . , userInfo (, , ).

:

- (void)playbackStateDidChange:(NSNotification *)notification {
    static NSString * const stateKey = @"MPMusicPlayerControllerPlaybackStateKey";
    NSNumber *number = [[notification userInfo] objectForKey:stateKey];
    MPMusicPlaybackState state = [number integerValue];
    // state is the new state
    MPMusicPlayerController *player = [notification object];
    // state may not be equal to player.playbackState
}
+8

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


All Articles