我正在开发一个iPhone在线无线电流应用程序。我使用Matt Gallaher的AudioStreamer类在SHOUTCast的电台中播放在线曲目。但问题是,AudioStreamer应用编程接口已经被废弃,无法播放各种广播频道。我在谷歌上搜索并找到了各种替代方案,包括: AVPlayer、MPMoviePlayer等。
请推荐哪个玩家最能满足要求。
发布于 2013-01-08 19:14:56
您可以使用MPMovieplayerviewcontroller。它是流媒体音频/视频的完美选择。我也是
在我的一个应用程序中使用它来流式播放音频&而且它看起来像iPhone的默认播放器。
下面是使用这个播放器的代码,就像我在我的项目中做的那样:
NSString *geturl = [[radiotablearray objectAtIndex:btntag]objectForKey:@"iurl"];
NSLog(@"geturl..%@",geturl);
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];
[moviePlayerController.moviePlayer play];另外,在App.And中添加mediaplayer和Avfoundation框架,在.h文件中添加或导入这两个框架:
#import <MediaPlayer/MediaPlayer.h>
#import <AVFoundation/AVFoundation.h>在.m文件中导入此文件(&I)。在.h文件中也像下面这样制作播放器的属性:
MPMoviePlayerViewController *moviePlayerController;
@property(strong,retain) MPMoviePlayerViewController *moviePlayerController;在你想要的地方添加方法,但也要根据你的需要修改代码,我只是把我的实现代码发给你,你只需要根据你的需求改变它。如果你有什么问题,尽管问我。祝你好运。
发布于 2015-12-19 17:39:07
// viewcontroller.h
MPMoviePlayerViewController *moviePlayer;
//viewcontroller.m这是在viewDidLoad中实现的
moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",@"http://sample url"]]];
[moviePlayer.moviePlayer prepareToPlay];
moviePlayer.view.hidden = YES;
[self.view addSubview:moviePlayer.view];
[moviePlayer.moviePlayer play];https://stackoverflow.com/questions/14213645
复制相似问题