码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2015-07-27 21:10:41      阅读:157      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!