I use AVPlayer to play long audio mp3 music (8 minutes), short musical compositions (1 to 3 minutes), but with such great musical instruments the music starts to play, but after playing a few random minutes (between 2 and 3:20 ), the player starts the track again from the very beginning. Although the player restarts the music, the status information (duration and current time) continues to be counted normally, without restarting, only restarting the sound. Does anyone have an idea?
The file I am reproducing is: http://storage-new.newjamendo.com/download/track/57864/mp31/
Player Code:
AVAudioSession *mySession = [AVAudioSession sharedInstance]; // Assign the Playback category to the audio session. NSError *audioSessionError = nil; [mySession setCategory: AVAudioSessionCategoryPlayback error: &audioSessionError]; if (audioSessionError != nil) { NSLog (@"Error setting audio session category."); return; } // Activate the audio session [mySession setActive: YES error: &audioSessionError]; if (audioSessionError != nil) { NSLog (@"Error activating audio session during initial setup."); return; } player = [AVPlayer playerWithURL:[NSURL URLWithString:url]]; [player play];
And this is how I track the current time information, which always takes account into account.
AVPlayerItem *item = player.currentItem; CMTime duration = [item duration]; CMTime currentTime = [item currentTime];
source share