It seems that this is a problem with iOS 11 that some people have run into when setting the currentPlaybackTime
after calling play()
. There was a work around posted on this apple dev forum here, but please find the code below (thanks to RunLoop).
I had just run into this exact problem. I managed to get around it
with the following code.
It creates a background thread that continuously checks the
currentPlaybackTime
of the player. As soon as currentPlaybackTime
is not the time I set it to be I set currentPlaybackTime
back to
what I wanted.
It feels like a terrible hack but it's working for me so far.
MPMusicPlayerController *player = [MPMusicPlayerController systemMusicPlayer];
player.currentPlaybackTime = _startTime;
[player play];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul);
dispatch_async(queue, ^{
while(true) {
if (player.currentPlaybackTime != _startTime) {
player.currentPlaybackTime = _startTime;
break;
}
}
});