简体   繁体   中英

IOS - Streaming and Downloading an Audio File

I am currently making an app that is capable of streaming a music file. The problem is, our client wants it that while we are streaming an audio file, the streamed bytes will also be saved in the local storage. Which means that the streamed audio file will also be saved on the device's storage. For example I have this m4a file streamed, when the user stops streaming the audio file, the streamed music file will be saved in the device's local storage for future use.

Is this possible? If it is, what library should I use?

Thanks.

Yes it is possible use AVFoundation framework for this and play your audio.

First drag AVFoundation framework from built phase section then import like this #import <AVFoundation/AVFoundation.h>

Then declare AVAudioPlayer in .h file of your view controller instance like this

AVAudioPlayer *myAudioPlayer;

In view controller.m put this code

NSURL *fileURL = // your url.   
myAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];
myAudioPlayer.numberOfLoops = -1; //infinite loop
[myAudioPlayer play];

Via this way you are able to play audio in your iOS device.hope it will help your for playing audio

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