简体   繁体   中英

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];

似乎问题是我正在播放的mp3文件是mpeg-1而且Apple文档说我必须使用mpeg-2,所以我刚刚更改为正确的版本,并且错误不会再次发生。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM