MPMusicPlaybackState按钮标题不更改

时间:2015-04-28 02:02:18

标签: ios mpmusicplayercontroller

我刚刚成功建立了一个音乐播放器。它查询用户的iTunes并根据查询播放歌曲。出于某种原因,按钮在播放状态更改时不会发生变化。我有两个和NSLog和Label,他们都引用它,但是当涉及到按钮时,没有任何反应。这是代码:

- (void) handle_PlaybackStateChanged: (id) notification {

MPMusicPlaybackState playbackState = [self.player playbackState];


if (playbackState == MPMusicPlaybackStatePaused) {

    self.textLabel.text = @"play";
    [PlayButton setTitle:@"STOP" forState:UIControlStateNormal]; // To set the title

    NSLog (@"This is paused");
    self.playBarButton.title = @"Play";

     self.PlayButton = PlayButton;


    [self.PlayButton setTitleColor:[UIColor redColor]      forState:UIControlStateNormal];


   } else if (playbackState == MPMusicPlaybackStatePlaying) {

    self.textLabel.text = @"pause";
    [PlayButton setTitle:@"Pause" forState:UIControlStateNormal];

    self.PlayButton = PauseButton;
    NSLog (@"This is playing");



} else if (playbackState == MPMusicPlaybackStateStopped) {

    self.textLabel.text = @"Play";
    self.PlayButton = PlayButton;


    [self.player stop];

}
}

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

我想出来了。我只需要在viewDidLoad

中添加以下代码
if ([musicPlayer playbackState] == MPMusicPlaybackStatePlaying) {

[playPauseButton setImage:[UIImage imageNamed:@"pauseButton.png"] forState:UIControlStateNormal];

} else {

[playPauseButton setImage:[UIImage imageNamed:@"playButton.png"] forState:UIControlStateNormal];
}