当前位置:首页 > Windows程序 > 正文

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

2021-03-28 Windows程序

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

[selfpresentViewController:self.mediaPickeranimated:YEScompletion: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了。

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/69211.html