如果您不想缓冲,请尝试通过MPMovieviewcontroller播放流媒体直播音频。
它是直播音频/视频的完美播放器。我也使用这个播放器在我的一个
播放现场音频流的应用程序。我认为你的所有要求都与此相符。尝试执行
。这是很容易实现also.Here是我的代码玩使用
MPMovieviewcontroller流音频:
NSURL *fileURL=[NSURL URLWithString:geturl];
NSLog(@"fileURL..%@",fileURL);
moviePlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:fileURL];
[moviePlayerController.moviePlayer prepareToPlay];
moviePlayerController.moviePlayer.shouldAutoplay=YES;
moviePlayerController.view.frame = self.view.frame;
[self presentMoviePlayerViewControllerAnimated:moviePlayerController];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(MPMoviePlayerDidExitFullscreen:) name:MPMoviePlayerDidExitFullscreenNotification object:nil];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
[moviePlayerController.moviePlayer play];
- (void)MPMoviePlayerDidExitFullscreen:(NSNotification *)notification
{
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerDidExitFullscreenNotification
object:nil];
[moviePlayerController.moviePlayer stop];
MPMoviePlayerController *player = [notification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[moviePlayerController dismissMoviePlayerViewControllerAnimated];
}
而对于后台播放我在info.plist中添加这些行。您还添加这些到PList:
![enter image description here](https://i.stack.imgur.com/IFOyt.png)
维沙尔,谢谢您的建议。你有任何示例代码,所以我可以看到你是如何实现这一点的?苹果文件谈论了很多关于视频和视频的观点。我只需要在后台播放音频。谢谢! – Paul
我编辑我的上面的答案看我如何使用MPMovieviewcontroller播放流音频... – Vishal
也使.m文件中的MPmovieviecontroller适当的属性,并添加它#import在.m文件中... –
Vishal