Reputation: 2521
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];
Upvotes: 7
Views: 999
Reputation: 2272
I have managed to fix this problem, it would appear (for me) that the server was sending the file as one block.
I don't know the ins and outs but the stream is now provided as a "ranged" stream (it is provided in segments I am told). Not only did this solve the problem but such things below started to work for me (as apposed to providing NaN).
float duration = CMTimeGetSeconds(self.avQueuePlayer.currentItem.duration);
I hope this helps, I am not being told much about what was changed on the server. Strangly my URL links worked on just about all other devices but I got this problem when playing from my App AND Safari.
Upvotes: 0
Reputation: 2521
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.
Upvotes: 1