iPhone progressive download audio player [closed]

老子叫甜甜 提交于 2019-12-20 10:57:52

问题


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


回答1:


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.




回答2:


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.




回答3:


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 



回答4:


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



来源:https://stackoverflow.com/questions/2536441/iphone-progressive-download-audio-player

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!