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?
Answered by tcollette1 in 710467022

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!

“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);

Accepted Answer

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!

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;

        }
MPMusicPlayerController currentPlaybackTime returns 0 on M1 Mac
 
 
Q