2012-09-29 44 views
-1

我試圖使用相同的按鈕來播放和停止我的電臺流,我的按鈕播放良好,然後當我按下它停止,它只停止幾秒鐘,然後開始播放。MPMoviePlayerController停止按鈕不起作用

這裏是我使用的代碼。

- (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];} 

}

+0

任何人反饋將不勝感激 – Luna

回答

0

每次按下該按鈕,創建電影播放器​​的新實例。因此,支票if (player.playbackState == MPMoviePlaybackStateStopped)將始終返回YES,從而啓動電影。