Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVPlayer not finishing the stream track

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];
like image 633
Roberto Ferraz Avatar asked Oct 21 '13 03:10

Roberto Ferraz


1 Answers

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.

like image 186
Roberto Ferraz Avatar answered Oct 14 '22 11:10

Roberto Ferraz