首页 > Windows开发 > 详细

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

时间:2015-07-27 21:09:37      阅读:326      评论:0      收藏:0      [点我收藏+]

一 今天有群友遇到问题说使用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了。

版权声明:本文为博主原创文章,未经博主允许不得转载。

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

原文:http://blog.csdn.net/jueyi1127/article/details/47089101

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!