Streaming Audio Files in iOS
Solution 1
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
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;
}
Solution 2
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.
Jason McCreary
I'm JMac - a software engineer in Louisville, KY working primarily on PHP and iOS applications. Creator Laravel Shift - the automated way to upgrade Laravel projects. Produced Getting Git - a comprehensive video series to help you learn Git. I believe in providing answers that teach. StackOverflow Tips: Tell us what you have tried? If asking about an error, include the error message and offending line. Learn the formatting options.
Updated on June 04, 2022Comments
-
Jason McCreary almost 2 years
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.
-
Jason McCreary almost 12 yearsI'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?
-
bitmapdata.com almost 12 yearsi 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: developer.apple.com/library/mac/#documentation/AudioVideo/…
-
Jason McCreary almost 12 yearsBut how. You did not use
AVPlayer
for the upload… Did you useNSURLConnection
? -
bitmapdata.com almost 12 yearsNo, directly upload using a FTP.
-
Jason McCreary almost 12 yearsOkay. I fear this may not meet my requirements. But I will look into these. Maybe they do…
-
Jason McCreary almost 12 yearsThis 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.