0

我正在开发一个流广播电台的应用程序。该视图包含一个按钮,按下该按钮后会调用MPMoviePlayerViewController. (请参阅此处此处的屏幕截图)。

播放按钮的 IBAction 如下所示:

- (IBAction)Play:(id)sender {

    NSURL *url = [NSURL URLWithString:@"http://fm.radiokfor.com:8080"];
    MPMoviePlayerViewController *playercontroller = [[MPMoviePlayerViewController alloc]initWithContentURL:url];


    [self presentViewController:playercontroller animated:NO completion:nil];

    playercontroller.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;

    [playercontroller.moviePlayer play];

}

我的问题是:有没有办法让我可以在没有 MPMoviePlayerController 在视图顶部的情况下播放流并允许我导航到其他选项卡?是否可以仅通过单击按钮在后台播放音频?

4

3 回答 3

3

You need to use one of the sanctioned uibackgroundmodes under your app's info.plist.

于 2013-08-07T08:20:37.123 回答
0

您应该使用MPMoviePlayerController而不是MPMoviePlayerViewController

于 2013-08-07T08:24:27.067 回答
-1

我使用以下方法修复了它:

- (IBAction)Play:(id)sender
{

    self.player = [[AVPlayer alloc] initWithURL:[NSURL URLWithString:@"http://fm.radiokfor.com:8080"]];
    [self.player play];
    self.radioStationLabel.text = @"Now playing: Radio KFOR";
}

- (IBAction)Stop:(id)sender
{

    [self.player pause];
    self.radioStationLabel.text = @"Press 'Play' to start stream";
}
于 2013-08-09T14:04:22.967 回答