Lens c play audio as it loads

I have an iphone design question regarding downloading and playing an audio file. Thanks to the Matt Gallagher AudioStreamer sample, I can transfer audio and play it back, but that will not save it locally on the phone later. Using NSURLConnection, I can load and save audio files, but I need to wait until I have downloaded them to launch my AVAudioPlayer, since the data property is read-only. I can not add to the buffer.

My question is, how can I start the download, but then start playing the file after it “loads” enough, but before it finishes? Is there another audio player besides AVAudioPlayer that I can feed to a file when it loads.

The only way I can do it now is to do both in different threads, but then, of course, I would dump the data twice.

Thoughts?

+2
source share
2 answers

I thought you could do it with AVAudioPlayer, but I have not tested it. I believe that I played audio without fully downloading AVPlayer:

self.player = [AVPlayer playerWithURL:assetUrl]; [player play]; 
0
source

I would use AVAudioSession along with MPMoviePlayerViewController.

 /** * Play audio session * * @version $Revision: 0.1 */ - (void)playAudioWithURL:(NSString *)audioURL { AVAudioSession *audioSession = [AVAudioSession sharedInstance]; NSError *setCategoryError = nil; [audioSession setCategory:AVAudioSessionCategoryPlayback error:&setCategoryError]; if (setCategoryError) { } NSError *activationError = nil; [audioSession setActive:YES error:&activationError]; if (activationError) { } MPMoviePlayerViewController *tempPlayer = [[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL URLWithString:[audioURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]; // Make sure we have airplay if([tempPlayer.moviePlayer respondsToSelector:@selector(setAllowsAirPlay:)]) { tempPlayer.moviePlayer.allowsAirPlay = YES; } tempPlayer.moviePlayer.shouldAutoplay = YES; tempPlayer.moviePlayer.useApplicationAudioSession = NO; [self presentMoviePlayerViewControllerAnimated:tempPlayer]; [tempPlayer.moviePlayer play]; [tempPlayer release]; }//end 
0
source

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


All Articles