MPMoviePlayerController停止按钮不起作用

时间:2012-09-29 02:39:17

标签: uibutton streaming mpmovieplayercontroller mpmovieplayer

我正在尝试使用相同的按钮来播放和停止我的收音机流,我的按钮播放正常,然后当我按下它停止时,它只停止几秒钟然后再次开始播放。

这是我正在使用的代码。

- (IBAction)playStream:(id)sender {
self.buttonPressed.selected = !self.buttonPressed.selected;

NSString *urlAddress = @"http://67.159.28.74:8730";
NSURL *url = [NSURL URLWithString:urlAddress];

MPMoviePlayerController *player = [[MPMoviePlayerController alloc]initWithContentURL:url];


player.movieSourceType = MPMovieSourceTypeStreaming;



player.view.hidden = YES;

self.myPlayer = player;

[self.view addSubview:self.myPlayer.view];



if (player.playbackState == MPMoviePlaybackStateStopped){
    [self.myPlayer play];}
else if (player.playbackState == MPMoviePlaybackStatePlaying){
   [self.myPlayer stop];}

}

1 个答案:

答案 0 :(得分:0)

每按一次按钮,都会创建一个新的电影播放器​​实例。因此,检查if (player.playbackState == MPMoviePlaybackStateStopped)将始终返回YES,从而启动电影。