3

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Jason McCreary
  • 71,546
  • 23
  • 135
  • 174

4 Answers4

2

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;
}
bitmapdata.com
  • 9,572
  • 5
  • 35
  • 43
  • I'll take a look at the sample code. But I see that this will handled playback, but you also said upload. What did you use for the upload? – Jason McCreary Aug 10 '12 at 16:14
  • i say, 'upload' means is .mp3 file upload to myServer. about 'blahblah.com/my_file.mp3'. The sample code is a skeleton. is the basic-code using a AVPlayer implement streaming audio or video play. For further information, please see the following: https://developer.apple.com/library/mac/#documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/00_Introduction.html#//apple_ref/doc/uid/TP40010188 – bitmapdata.com Aug 10 '12 at 16:17
  • But *how*. You did not use `AVPlayer` for the upload… Did you use `NSURLConnection`? – Jason McCreary Aug 10 '12 at 16:21
  • No, directly upload using a FTP. – bitmapdata.com Aug 10 '12 at 16:22
  • Okay. I fear this may not meet my requirements. But I will look into these. Maybe they do… – Jason McCreary Aug 10 '12 at 16:24
1

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.

tumtumtum
  • 1,052
  • 9
  • 11
0

Yes, AudioStreamer is really good till now what I have used and searched through.

But with AudioStreamer, there are certain changes needed when trying to stream in background, also when you are creating 2 instances, and lots more.....

https://github.com/mattgallagher/AudioStreamer/

You can find 2-3 questions regarding the same in my profile also...

DShah
  • 9,768
  • 11
  • 71
  • 127
0

I think what you are looking to do are uploading and downloading files from and to a server not streaming. For downloading, you can use NSURLConnection/ NSURLRequest. For uploading, you can use HTTP POST method. There is also an old third party library called ASIHTTPRequest. There are quite a bit of samples on these topics on the Internet.

Community
  • 1
  • 1
user523234
  • 14,323
  • 10
  • 62
  • 102
  • This would require polling the server for when the resource is ready. I want to send data to the server as it is available, and keep the connection until it returns all data (in this case data is an audio file). So I am indeed looking for sockets/streaming. – Jason McCreary Aug 13 '12 at 12:49