I am using AVPlayer to play long audio mp3 stream music (8 minutes), short musics (1 to 3 minutes) plays perfectly, but with these bigger musics the music starts playing, but after play some random minutes (between 2 and 3:20) the player starts the track again from the beginning. Although the player restart the music, the status information (duration and current time) keeps counting normally, without restart, just the audio restarts. Someone has an idea?
The file I am playing is this: http://storage-new.newjamendo.com/download/track/57864/mp31/
The 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 here is how I track the information about the current time, that keeps counting normally.
AVPlayerItem *item = player.currentItem;
CMTime duration = [item duration];
CMTime currentTime = [item currentTime];
Seems that the problem is that the mp3 file I was streaming was a mpeg-1 and the Apple documentation says that I have to use mpeg-2, so I have just changed to the correct version, and the error is not happening again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With