如何在iOS应用程序中播放m3u音频流
我正在尝试使用Xcode 4.5.2创建一个iOS/iPhone无线电应用程序 我想流@”http://xx.xxxxxxx.com/8111/radio.m3u“具有播放、暂停、音量控制和后台播放功能/多任务处理功能 到目前为止,我已经添加了如何在iOS应用程序中播放m3u音频流,ios,xcode,audio,avfoundation,mpmovieplayer,Ios,Xcode,Audio,Avfoundation,Mpmovieplayer,我正在尝试使用Xcode 4.5.2创建一个iOS/iPhone无线电应用程序 我想流@”http://xx.xxxxxxx.com/8111/radio.m3u“具有播放、暂停、音量控制和后台播放功能/多任务处理功能 到目前为止,我已经添加了AVFoundation、Mediaplayer和AudioToolBox框架。我在xib中添加了播放、暂停和滑块对象 ViewController.h @interface ViewController : UIViewController @pro
AVFoundation
、Mediaplayer
和AudioToolBox
框架。我在xib中添加了播放、暂停和滑块对象
ViewController.h
@interface ViewController : UIViewController
@property (strong,nonatomic) MPMoviePlayerController *myPlayer;
@property (weak, nonatomic) IBOutlet UISlider *myslider;
- (IBAction)playButtonPressed;
- (IBAction)myslider:(id)sender;
@end
ViewController.m
#import "ViewController.h"
#import <MediaPlayer/MediaPlayer.h>
@interface ViewController ()
{
UISlider *volumeSlider;
}
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
UIBackgroundTaskIdentifier newTaskId = UIBackgroundTaskInvalid;
newTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL];
}
- (IBAction)playButtonPressed;
{
NSString *urlAddress = @"http://xxxxxxx.com/8111/listen.m3u";
NSURL *url = [NSURL URLWithString:urlAddress];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc]initWithContentURL:url];
player.movieSourceType = MPMovieSourceTypeStreaming;
[player prepareToPlay];
self.myPlayer = player;
[self.view addSubview:self.myPlayer.view];
[self.myPlayer play];
}
- (IBAction)stopButtonPressed;
{
[self.myPlayer stop];
}
- (IBAction)myslider:(id)sender
{
MPVolumeView *volumeView = [[MPVolumeView alloc] initWithFrame: CGRectMake(10, 10, 200, 40)];
[volumeSlider addSubview:volumeView];
[volumeView sizeToFit];
}
ViewController.h
@界面ViewController:UIViewController
@属性(强,非原子)MPMoviePlayerController*myPlayer;
@性质(弱,非原子)IBUISLIDER*myslider;
-(iAction)按下播放按钮;
-(iAction)myslider:(id)发送方;
@结束
ViewController.m
#导入“ViewController.h”
#进口
@界面视图控制器()
{
UISlider*体积滑块;
}
@结束
@实现视图控制器
-(无效)viewDidLoad
{
[超级视图下载];
[[UIApplication sharedApplication]开始接收RemoteControlEvents];
UIBackgroundTaskIdentifier newTaskId=UIBackgroundTaskInvalid;
newTaskId=[[UIApplication sharedApplication]beginBackgroundTaskWithExpirationHandler:NULL];
}
-(iAction)按下播放按钮;
{
NSString*urlAddress=@”http://xxxxxxx.com/8111/listen.m3u";
NSURL*url=[NSURL URLWithString:urlAddress];
MPMoviePlayerController*player=[[MPMoviePlayerController alloc]initWithContentURL:url];
player.movieSourceType=mpmoviesourcetype流媒体;
[玩家准备玩];
self.myPlayer=player;
[self.view addSubview:self.myPlayer.view];
[self.myPlayer play];
}
-(i)按下停止按钮;
{
[self.myPlayer-stop];
}
-(iAction)myslider:(id)发送方
{
MPVolumeView*volumeView=[[MPVolumeView alloc]initWithFrame:CGRectMake(10,10200,40)];
[volumeSlider添加子视图:volumeView];
[volumeView sizeToFit];
}
实现这一点有两种方法
@interface ViewController ()
{
UISlider *volumeSlider;
MPMoviePlayerController *player;
}
@end
- (IBAction)playButtonPressed;
{
NSString *urlAddress = @"http://xxxxxxx.com/8111/listen.m3u";
NSURL *url = [NSURL URLWithString:urlAddress];
if(nil != player)
{
player = nil; // Alternatively you can stop and restart with the different stream.
}
player = [[MPMoviePlayerController alloc]initWithContentURL:url];
player.movieSourceType = MPMovieSourceTypeStreaming;
[player prepareToPlay];
self.myPlayer = player;
[self.view addSubview:self.myPlayer.view];
[self.myPlayer play];
}
有人能帮我翻译一下上面的代码吗?谢谢谢谢你,你能告诉我上面的代码有什么问题吗?请,同样的问题,但在手表应用程序上?有什么例子吗?