iPhone progressive download audio player [closed]
Asked Answered
D

4

9

I'm trying to implement a progressive download audio player for the iPhone, using http and fixed size mp3-files.

I found the AudioStreamer project but it seems very complicated and works best with endless streams.

I need to be able to find out the total length of audio files and I also need to be able to seek in the files. I found a hacked deviation from AudioStreamer but it doesn't seem to work very well for me. http://www.saygoodnight.com/?p=14

I'm wondering if there is a simpler way to achieve my goals or if there are some better working samples out there? I found the bass library but not much documentation about it.

/Br Johannes

Duchamp answered 29/3, 2010 at 7:49 Comment(1)
I'm adding a bounty to this question as I have the same question - with the hopes of saving the content as I download/play it.Doralyn
C
8

There's unfortunately nothing simple about playing audio streams on the iPhone. Here's the article that got me started: Streaming and playing an MP3 stream

It's an OSX project, but most of it will work with the iPhone too. As for getting the full play time of it, you'd probably have to figure that out based on the content-length property of http header, provided it's a CBR file. Otherwise, I imagine you'd have to download the entire file before determining that.

Choke answered 29/3, 2010 at 21:44 Comment(1)
+1 for linking to cocoawithlove, i also got an app out there which i only could get running with this ressource.Nett
S
5

If you only need to play MP3 files, why are you writing your own downloader/player? You have a few options built into iOS, each of which support progressive download and MP3 playback:

  • MPMoviePlayerController
  • AVPlayer
  • Safari <audio> player

I've personally had issues with the progressive download capabilities of MPMoviePlayerController and AVPlayer, so perhaps this is your issue also. I've found that these players try to be smart by requesting the mp3 multiple times, checking to see if the server supports progressive download via http range offsets. But when the server doesn't support range offsets the file is downloaded multiple times, eating bandwidth (!).

In my latest project I embedded a UIWebView having a html <audio> tag embedded. The Safari player seems to behave better than AVPlayer and MPMoviePlayerController, but it had its own caveats as well. For one, getting autoplay to work was a PITA.

Subtotal answered 25/2, 2011 at 18:42 Comment(0)
F
4

There's a really good chapter about streaming audio in iPhone Cool Projects. http://apress.com/book/view/9781430223573 It shows a simpler approach then AudioStreamer (Using NSURLConnection instead of CFNetwork), better suited for progressive downloading, and no multi threading code.

And for finding out the size of the audio file you can use [response expectedContentLength] in

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 
Fumble answered 16/2, 2011 at 13:33 Comment(0)
M
1

I know this is a rather old post, but wanted to suggest a solid library that is open source. It is based on Matt Gallagher's original post recommended by @pzearfoss above. The current version uses AudioUnits now, rather than the AudioQueue classes, so it gives you access to the raw PCM samples for any manipulation you want to make (filtering, etc.) before playback. It also gives you progressive download capabilities for free, with rather minimal effort. The library seems to be actively updated which is a huge plus!

StreamingKit by @tumtumtum

Moorer answered 4/6, 2014 at 13:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.