【发布时间】:2015-02-12 17:21:50
【问题描述】:
我使用 MPMusicPlayerController 创建了一个非常简单的音乐播放器,除了停止按钮(见下图)外,它工作正常。当音乐播放并按下停止按钮时,应用程序不再播放。我试图在后台终止它,但应用程序不起作用。在中控上按下播放后,我可以再次使用该应用程序(图二)。 还有我的代码
#import "ViewController.h"
#import <MediaPlayer/MediaPlayer.h>
@interface ViewController ()
{
MPMusicPlayerController *playerController;
MPMediaQuery *query;
}
@end
@implementation ViewController
@synthesize musicTitleLabel;
- (void)viewDidLoad {
[super viewDidLoad];
playerController = [[MPMusicPlayerController alloc] init];
}
- (IBAction)playPressed:(id)sender {
query = [MPMediaQuery songsQuery];
MPMediaItem *item = [[query collections] objectAtIndex:0];
[playerController setNowPlayingItem:item];
[playerController play];
NSString *titleString = [item valueForProperty:MPMediaItemPropertyTitle];
musicTitleLabel.text = [NSString stringWithFormat:@"%@",titleString];
}
- (IBAction)pausePressed:(id)sender {
[playerController pause];
}
- (IBAction)stopPressed:(id)sender {
[playerController stop];
}
我该如何解决这个问题? Stop方法的作用是什么?
【问题讨论】:
标签: ios iphone xcode mpmusicplayercontroller