简体   繁体   English

在iOS客户端上使用HTTP Live Streaming播放音频文件流,而不会将UI丢失到Quick Time

[英]Play audio file stream using HTTP Live Streaming on iOS client without losing UI to Quick Time

I have a HTTP Live streaming server setup that serves segmented mp3 audio content (the URL points to playlist.m3u8 index file). 我有一个HTTP Live流媒体服务器设置,提供分段的mp3音频内容(URL指向playlist.m3u8索引文件)。 I need to build an iOS client application to consume this audio stream without using any standard Apple controls/UI. 我需要构建一个iOS客户端应用程序来使用此音频流, 而无需使用任何标准的Apple控件/ UI。 It should play the stream in the background and I want to use my own custom UI for providing the controls. 它应该在后台播放流,我想使用我自己的自定义UI来提供控件。

Since the content is purely audio, I don't want to use MPMoviePlayerController class as it takes over the UI. 由于内容纯粹是音频,我不想在接管UI时使用MPMoviePlayerController类。 I have tried using AVAudioPlayer, although it is not meant for network streams, which unsurprisingly fails to playback with an error code "-43" : NSOSStatusErrorDomain. 我尝试过使用AVAudioPlayer,虽然它不适用于网络流,但不出所料地无法使用错误代码“-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. 我还尝试创建一个高度和宽度为1像素的UIWebView,并将其指向服务器上的playlist.m3u8文件。 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. 这很有效,但不幸的是我仍然失去了UI,因为UIWebView只是将播放的任务委托给QuickTime播放器,该播放器在我的应用程序中以iOS 3.xx设备全屏启动。

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. 基本上,在我看来,Apple没有提供任何客户端API来消费HTTP Live Streaming 音频流,开发人员被迫放弃用户界面到QuickTime播放器,该播放器播放带有QT徽标的流播放屏幕。 ughh... 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. 否则,我的计划B是放弃HTTP Live Streaming并使用着名的Matt Gallagher经典流媒体实现。 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. 但是,我有点担心苹果指南明确暗示,对于预计会通过蜂窝网络(我的应用程序)发送大量音频或视频内容的应用程序需要使用HTTP Live流媒体。 Does this mean that my plan B implementation is prone to rejection by Apple? 这是否意味着我的计划B实施容易被Apple拒绝? Any ways to circumvent this guideline? 有什么方法可以绕过这个指南吗?

http://developer.apple.com/library/ios/#documentation/MediaPlayer/Reference/MPMoviePlayerController_Class/Reference/Reference.html 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. 在iOS 3.1及更早版本中,此类仅实现了全屏电影播放器​​。

A quick test using Apple's sample streams proves what you want to do is possible. 使用Apple的样本流进行快速测试证明了您想要做的事情。

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

I used the audio streamer by Matt Gallagher in one of my apps. 我在我的一个应用程序中使用了Matt Gallagher的音频流 It's an internet radio app pretty much like Pandora and LastFM. 这是一个互联网广播应用程序,非常像Pandora和LastFM。 And yes it was accepted by Apple and has been in the App Store since then. 是的,它被Apple接受,从那时起一直在App Store。

So in my opinion, your plan B is actually not that risky. 所以在我看来,你的计划B实际上并没有那么大的风险。 :-) :-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM