I'm making an app that will play audiobooks synced with iTunes. Is there a way my player can remember the playback position? Or do I need to implement this myself with some sort of database?
I'm testing on iOS 8.4
I'm making an app that will play audiobooks synced with iTunes. Is there a way my player can remember the playback position? Or do I need to implement this myself with some sort of database?
I'm testing on iOS 8.4
The key is to set the current playback time to the bookmark time of the mpmediaitem before playing.
Here's an example:
[self.player setQueueWithItemCollection:self.collection];
self.player.currentPlaybackTime = [self.collection.items[0] bookmarkTime];
[self.player play];
An audiobook file will automatically remember its playback position, and when asked to play again later, will resume from that position - that is a built-in feature of the Music app (now iBooks) and therefore of the MPMusicPlayerController.
However, you will notice that the Music app can lose track of the currently playing item (if the user restarts the device). And of course the user might change the currently playing item manually.
Thus, if you want your app to return to what it was playing previously, you will have to save that currently playing item information yourself. And so you might as well save the current playback position too, thus making yourself even more reliable than the Music app.
[MPMusicPlayerController systemMusicPlayer]
, not applicationMusicPlayer
. That's what my app uses. And thus it gets the same interplay with iBooks. –
Maihem ApplicationMusicPlayer
and don't try to interact with the Music app / iBooks — because, in iOS 8.4, I think you'll fail. –
Maihem bookmarkTime
or through valueForProperty
with MPMediaItemPropertyBookmarkTime
. Nevertheless this does not solve the bug I'm talking about, which is that the MPMusicPlayerController is failing to report its own nowPlayingItem
and currentPlaybackTime
correctly. –
Maihem © 2022 - 2024 — McMap. All rights reserved.