AVPlayer does not terminate the stream

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]; 
+6
source share
2 answers

The problem seems to be that the mp3 file I was broadcasting was mpeg-1, and the Apple documentation says I need to use mpeg-2, so I just changed it to the correct version and the error does not occur again.

+1
source

I managed to fix this problem, it seemed to me that the server sends the file as a single block.

I do not know the inputs and outputs, but the stream is now provided as a "distant" stream (it is provided in the segments that I am told about). Not only did this solve the problem, but such things below started to work for me (as was provided for providing NaN).

 float duration = CMTimeGetSeconds(self.avQueuePlayer.currentItem.duration); 

I hope this helps, they don’t tell me about what has been changed on the server. It’s strange that my URLs worked with almost all other devices, but I had this problem when playing from my application and Safari.

0
source

Source: https://habr.com/ru/post/956375/


All Articles