14

I have a HTTP Live streaming server setup that serves segmented mp3 audio content (the URL points to playlist.m3u8 index file). I need to build an iOS client application to consume this audio stream without using any standard Apple controls/UI. It should play the stream in the background and I want to use my own custom UI for providing the controls.

Since the content is purely audio, I don't want to use MPMoviePlayerController class as it takes over the UI. I have tried using AVAudioPlayer, although it is not meant for network streams, which unsurprisingly fails to playback with an error code "-43" : NSOSStatusErrorDomain.

I have also tried to create an UIWebView with 1 pixel height and width and pointing it to the playlist.m3u8 file on the server. This works but unfortunately I still lose UI since UIWebView simply delegates the task of playing back to QuickTime player which launches within my app with full screen for iOS 3.xx devices.

Basically, it seem to me that Apple has not provided any client APIs for consuming HTTP Live Streaming audio streams and developers are forced to relinquish the UI to QuickTime player which plays the stream with the QT logo usurping the screen. ughh...

I would love to know if anyone has suggestions to help me with the above. Otherwise, my plan B is to abandon HTTP Live Streaming and use the famous Matt Gallagher classic streaming implementation. However, I am a bit worried about Apples guidelines that are clearly suggesting that for Apps that are expected to send large amount of Audio or Video content over cellular networks (which my app is) are required to use HTTP Live streaming. Does this mean that my plan B implementation is prone to rejection by Apple? Any ways to circumvent this guideline?

Cœur
  • 37,241
  • 25
  • 195
  • 267
bhavinb
  • 3,278
  • 2
  • 28
  • 26

2 Answers2

13

http://developer.apple.com/library/ios/#documentation/MediaPlayer/Reference/MPMoviePlayerController_Class/Reference/Reference.html

The docs say:

Playback occurs in a view owned by the movie player and takes place either fullscreen or inline.

In iOS 3.1 and earlier, this class implemented a full-screen movie player only.

A quick test using Apple's sample streams proves what you want to do is possible.

MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"http://devimages.apple.com/iphone/samples/bipbop/gear4/prog_index.m3u8"]];
player.movieSourceType = MPMovieSourceTypeStreaming;
player.view.hidden = YES;
[self.view addSubview:player.view];
[player play];
SteveB
  • 652
  • 3
  • 12
  • 1
    the question mentioned "...which launches within my app with full screen for iOS 3.xx devices". I know about the resizable View possibility and the ability to hide it in iPhone 4.0 and later (since iOS 3.2 was iPad only, after iOS 3.1.x, there is directly iOS 4.0 for the iPhone). The API `player.view.hidden = YES;` is only possible in iOS 3.2 and later which means for iPhones having iOS 4.0 and above. Hence this is not a feasible option as I want to support iPhones on iOS3.x and above in my app – bhavinb Mar 16 '11 at 06:04
  • 2
    Gotcha. Sorry I missed the iOS requirement in the question. However, you may want to seriously consider how much effort you want to put into devices running 3.x. I helped build an app that has over a half million downloads and 93% of users are running 4.0 or higher. Also see this link: http://www.quora.com/What-proportion-of-all-iPhone-owners-use-iOS4-*-today – SteveB Mar 21 '11 at 18:59
  • You're gonna have to copy and paste that link because the asterisk is messing it up. Sorry I couldn't get it to link properly. – SteveB Mar 21 '11 at 19:01
  • I dont have this iOS limitation, so I tried this solution. Im streaming content using icecast, but when I run the sample code I get this crash: 'An AVPlayerItem cannot be associated with more than one instance of AVPlayer' Any Ideas why? – gonso Nov 18 '11 at 13:14
  • @gonso Open a new question for your problem and post the code in there. Add the link for the new question in these comments and I'll take a look at it. – SteveB Nov 22 '11 at 13:37
  • @SteveB: nice link for number of iOS users for different versions. – viral May 19 '12 at 10:33
5

I used the audio streamer by Matt Gallagher in one of my apps. It's an internet radio app pretty much like Pandora and LastFM. And yes it was accepted by Apple and has been in the App Store since then.

So in my opinion, your plan B is actually not that risky. :-)

Di Wu
  • 6,436
  • 3
  • 35
  • 51
  • Thanks for the info. Did you submit the app before 2010-Feb-05? Looking at Apple's guideline document revision history, that is when they issued the mandate about apps requiring to use HTTP Live Streaming for high b/w media streaming. I am guessing they may have made their review policy stricter only for apps submitted to store after that guideline was publicly announced. – bhavinb Jan 18 '11 at 07:03
  • Hmmm.. I submitted around September 2010, and got approved in the following October. – Di Wu Jan 18 '11 at 07:21