MPMediaPickerController 选取本地音频 在模拟器运行出错

一 今天有群友遇到问题说使用MPMediaPickerController  会崩溃。

[self presentViewController:self.mediaPicker animated:YES completion:nil];


二 我运行了下,在真机上是ok的,模拟器应该加上以下代码

1. MPMediaPickerController不会在模拟器中运行。苹果公司指出这下“你好音乐播放器”中的“iPod库访问编程指南”中。该说明称: 注意:要按照这些步骤,你需要拧置备 该模拟器有没有访问拧开了iPod的音乐库。 

MPMediaPickerController *picker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeAnyAudio];
[picker setDelegate:self];
[picker setAllowsPickingMultipleItems:YES];
[picker setPrompt:NSLocalizedString(@"Add songs to play","Prompt in media item picker")];
@try {
 [picker loadView]; // Will throw an exception in iOS simulator
 [self presentViewController:picker animated:YES completion:nil];
}
@catch (NSException *exception) {
 [[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Oops!",@"Error title")
        message:NSLocalizedString(@"The music library is not available.",@"Error message when MPMediaPickerController fails to load") 
        delegate:nil 
      cancelButtonTitle:@"OK" 
      otherButtonTitles:nil] show];
}

2. storyboard(故事板),你可以尝试一下:
- (IBAction)showPicker:(id)sender
{
#if TARGET_IPHONE_SIMULATOR
 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"playerTest"
             message:@"Media picker didn't work in simulator, please run this app on device"
             delegate:nil
           cancelButtonTitle:@"OK"
           otherButtonTitles:nil];
 [alert show];
#else
 [self performSegueWithIdentifier:@"ShowPickerViewSegue" sender:self];
#endif
}

ok了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值