I need to send and receive audio files within my app. To be more performant and keep an open connection, I am looking to stream this data.
I have looked at things like HTTP Live Streaming and AudioStreamer based on answers to questions. However, these seem to be for continuous streaming, 1-way (read). Whereas I am sending a finite audio file (> 10 seconds) and then receiving one back.
I am familiar with NSURLConnection and have reviewed this answer. But again, this uses a continuous, 1-way stream.
I would appreciate any recommend on the architecture to accomplish the above to help me get started.
In general, the AVAudioPlayer uses music playback. However, this framework does not support streaming. So using AVPlayer streaming can be achieved. Usually the developers AVPlayer purposes only know that can play video, but can also play music.
I look at the following Apple's sample code is recommended.this is using a AVPlayer
StitchedStreamPlayer
I upload to myServer Tested, .mp3 also perfectly
3G, wifi tested in both environments. although sample code, It was surprisingly works perfectly. mp3 file upload your server. Try to test right now. Will work well.
And If you want to play in the background, the following code don't forget:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
AVAudioSession* audio = [[AVAudioSession alloc] init];
[audio setCategory: AVAudioSessionCategoryPlayback error: nil];
[audio setActive: YES error: nil];
return YES;
}
For playback form the server my Audjustable project (https://github.com/tumtumtum/audjustable) fixes most of the problems in the original AudioStreamer project and includes gapless playback and decoupled audio data source to allow for things like error-recovery, encryption etc. Completely open source...
If you want to upload audio data to the server you can do it many ways but NSURLConnection would seem to be the easiest way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With