Jason McCreary
Jason McCreary

Reputation: 72961

Streaming Audio Files in iOS

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.

Upvotes: 3

Views: 12292

Answers (4)

tumtumtum
tumtumtum

Reputation: 1162

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.

Upvotes: 1

user523234
user523234

Reputation: 14834

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.

Upvotes: 0

DShah
DShah

Reputation: 9866

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...

Upvotes: 0

bitmapdata.com
bitmapdata.com

Reputation: 9600

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;
}

Upvotes: 2

Related Questions