MPMusicPlayerController currentPlaybackTime returns 0 on M1 Mac

I have an existing iOS app that uses MPMusicPlayerController systemMusicPlayer. When running on a MacBook with M1 processor, calling currentPlaybackTime returns 0 during play. Once paused, the correct playtime is returned.

Anyone else having this issue or have an idea of how to get the correct playtime?

Accepted Reply

Just came across this post. I had this issue when I converted my iOS jukebox app to Mac Catalyst last year. I also discovered that changing the playback state would update playback time, so I added a play() command that is triggered in my one second Timer, and that solved my problem!

  • Thanks so much for sharing! It works exactly as you describe. Any unexpected consequences that you've noticed? I'm checking to be sure the music player is playing (otherwise, pause get unpaused) but it seems to be reliable. Such a shame that code arounds like this have to be shared in dev forums rather than iOS bugs being addressed. But I do appreciate you sharing your solution!

Add a Comment

Replies

“Apple Silicon”

Giving a bump. I'm still unable to get currentPlaybackTime from a track playing in MPMusicPlayerController while it's playing. Once it's paused, the correct time will be returned, but if started playing again, the time continues to be reported as the time of the previous pause. Here's the code I use in an iOS app running on a Mac M1. Anyone have any advice or is anyone else having the same trouble?

        NSLog(@"current playtime is %f", [MPMusicPlayerController systemMusicPlayer].currentPlaybackTime);

Just came across this post. I had this issue when I converted my iOS jukebox app to Mac Catalyst last year. I also discovered that changing the playback state would update playback time, so I added a play() command that is triggered in my one second Timer, and that solved my problem!

  • Thanks so much for sharing! It works exactly as you describe. Any unexpected consequences that you've noticed? I'm checking to be sure the music player is playing (otherwise, pause get unpaused) but it seems to be reliable. Such a shame that code arounds like this have to be shared in dev forums rather than iOS bugs being addressed. But I do appreciate you sharing your solution!

Add a Comment

Yeah, I posted about it on Stack Overflow when I was stuck like you, and then answered my own question, including the code snippet I used. No weird side effects, the overhead is negligible, just have to remember you can’t control play/pause in Music while your app is in use. Glad you were able to get a fix from it, too!

I added this code to my existing one second timer code and it works pretty well. As you mentioned, if running on an M1 Mac, pausing in the Music app will be overridden by this, but it functions as expected in iOS.

if ((previousPlaybackTime == musicPlayer.currentPlaybackTime) &&

            ([musicPlayer playbackState] == MPMusicPlaybackStatePlaying))

        {

            NSLog(@">>>update time is same as one second ago and state is playing so try calling play to trigger update");

            musicPlayer.play;

        }
  • This is close enough to my solution, just using the playback state instead of a boolean variable. I discovered that when I upgraded to Monterey this month my MPMusicPlayerControllerNowPlayingItemDidChange notification began giving me the same treatment: work once and done, leading to yet another code around. I posted about it here around the time I came across this post. If you have the same problem, please drop a comment about any ideas you might have as well!

Add a Comment