//-(void)selectLocalMusic{
//CGFloat version = [UIDevice currentDevice].systemVersion.floatValue;
//
//if(version>= 9.3f)
//{
//MPMediaLibraryAuthorizationStatus authStatus = [MPMediaLibrary authorizationStatus];
//if (authStatus == MPMediaLibraryAuthorizationStatusNotDetermined ) {
//[MPMediaLibrary requestAuthorization:^( MPMediaLibraryAuthorizationStatus status) {
//if (status == MPMediaLibraryAuthorizationStatusAuthorized) {
//dispatch_async(dispatch_get_main_queue(), ^{
//[self openLocalMusic];
//});
//}
//}];
//}
//else if (authStatus == MPMediaLibraryAuthorizationStatusAuthorized)
//{
//[self openLocalMusic];
//}
//else
//{
//[self.view setAlertControllerWithTitle:@"提示" message:@"请前往设置->隐私->媒体与Apple Music开通音乐访问权限" actionTitle:@"确定"];
//}
//}
//else
//{
//[self openLocalMusic];
//}
//}
//-(void)openLocalMusic{
////获取本地歌曲列表信息
//MPMediaQuery *allMp3 = [[MPMediaQuery alloc] init];
//MPMediaPropertyPredicate *albumNamePredicate =
//[MPMediaPropertyPredicate predicateWithValue:[NSNumber numberWithInt:MPMediaTypeMusic ] forProperty: MPMediaItemPropertyMediaType];
//[allMp3 addFilterPredicate:albumNamePredicate];
//
//for (MPMediaItem *song in [allMp3 items]) {
//NSLog (@"名称:%@, URL:%@,歌手名称:%@", song.title, song.assetURL,song.artist);
//NSLog (@"专辑名称:%@", song.albumTitle);
//}
//
//
////创建MPMediaPickerController对象
//MPMediaPickerController *mpc = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeAnyAudio];
////为MPMediaPickerController设置委托
//mpc.delegate =self;
////设置选择音乐的提示文字。
//mpc.prompt =@"请选择背景音乐";
////设置是否允许进行多选
//mpc.allowsPickingMultipleItems = NO;
////设置是否允许选择云端音乐
//mpc.showsCloudItems =NO;
//
//mpc.showsItemsWithProtectedAssets = NO;
//
//[[self parentViewController] presentViewController:mpc animated:YES completion:^{
////
//}];
//}
#pragma mark - MediaPicker delegate
//当用户选择指定音乐时激发该方法,mediaItemCollection代表用户选择的音乐
- (void)mediaPicker: (MPMediaPickerController*)mediaPicker didPickMediaItems:(MPMediaItemCollection*)mediaItemCollection
{
[[selfparentViewController]dismissViewControllerAnimated:YEScompletion:^{
//[self.delegate musicPlayed:YES];
}];
for(MPMediaItem* itemin[mediaItemCollectionitems]) {
NSString* title = item.title;
NSURL* url = item.assetURL;
TEBackgroundMusicModel* model = [[TEBackgroundMusicModelalloc]init];
model.musicName= [titlestringByAppendingString:@" (本地)"];
model.isLocal=YES;
model.isSelected=YES;
if([self.musicModelscount] >3&& [self.musicModelsobjectAtIndex:2].isLocal)
{
[self.musicModelsremoveObjectAtIndex:2];
}
//copy
NSFileManager*fileManager = [NSFileManagerdefaultManager];
NSString*directryPath = [[[NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES)lastObject]stringByAppendingPathComponent:@"DownloadMagicExpressions"]stringByAppendingPathComponent:@"musics"];
if(![fileManagerfileExistsAtPath:directryPath])
{
[fileManagercreateDirectoryAtPath:directryPathwithIntermediateDirectories:YESattributes:nilerror:nil];
}
NSString* filePath = [directryPathstringByAppendingPathComponent:@"local.mp3"];
[[NSFileManagerdefaultManager]removeItemAtPath:filePatherror:nil];
[TEExportMP3FileexportMP3:urltoFileUrl:filePath];
model.musicURL= [NSURLfileURLWithPath:filePath];
[self.musicModelsinsertObject:modelatIndex:2];
NSRangerange =NSMakeRange(0,1);
NSIndexSet*sectionToReload = [NSIndexSetindexSetWithIndexesInRange:range];
[self.tableViewreloadSections:sectionToReloadwithRowAnimation:UITableViewRowAnimationRight];
}
}
//点击取消按钮触发的方法
- (void)mediaPickerDidCancel:(MPMediaPickerController*)mediaPicker
{
[[selfparentViewController]dismissViewControllerAnimated:YEScompletion:^{
TEMusicViewCell*cell = (TEMusicViewCell*)[self.tableViewcellForRowAtIndexPath:[NSIndexPathindexPathForRow:1inSection:0]];
cell.selectedImageView.hidden=NO;
cell.selected=YES;
[self.tableViewselectRowAtIndexPath:[NSIndexPathindexPathForRow:1inSection:0]animated:NOscrollPosition:UITableViewScrollPositionNone];
}];NSLog(@"用户取消了选择");
}
网友评论