首页 > 分享 > itunes 歌曲导出 和上传

itunes 歌曲导出 和上传

app要求把iPhone本地歌曲导出到项目上传到服务器 

   源代码 :

 MPMediaQuery *everything = [[MPMediaQuery alloc] init];

    // 读取条件

    MPMediaPropertyPredicate *albumNamePredicate =

    [MPMediaPropertyPredicate predicateWithValue:[NSNumber numberWithInt:MPMediaTypeMusic ] forProperty: MPMediaItemPropertyMediaType];

    [everything addFilterPredicate:albumNamePredicate];

    NSLog(@"Logging items from a generic query...");

    NSArray *itemsFromGenericQuery = [everything items];

    for (MPMediaItem *song in itemsFromGenericQuery) {

}

 AVURLAsset *songAsset = [AVURLAsset URLAssetWithURL:url options:nil];

            NSLog (@"compatible presets for songAsset: %@",[AVAssetExportSession exportPresetsCompatibleWithAsset:songAsset]);

            NSArray *ar = [AVAssetExportSession exportPresetsCompatibleWithAsset: songAsset];

            NSLog(@"ar==%@", ar);

            AVAssetExportSession *exporter = [[AVAssetExportSession alloc]

                                              initWithAsset: songAsset

                                              presetName:AVAssetExportPresetAppleM4A];

            NSLog (@"created exporter. supportedFileTypes: %@", exporter.supportedFileTypes);

            exporter.outputFileType = @"com.apple.m4a-audio";

            NSString *exportFile = [documentsDirectoryPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.m4a",name];

            NSError *error1;

            if([fileManager fileExistsAtPath:exportFile])

            {

                [fileManager removeItemAtPath:exportFile error:&error1];

            }

            NSURL* exportURL = [NSURL fileURLWithPath:exportFile] ;

            exporter.outputURL = exportURL;

            // do the export

            [exporter exportAsynchronouslyWithCompletionHandler:^

             {

                 int exportStatus = exporter.status;

                 switch (exportStatus) {

                     case AVAssetExportSessionStatusFailed: {

                         // log error to text view

                         NSError *exportError = exporter.error;

                         NSLog (@"AVAssetExportSessionStatusFailed: %@", exportError);

                         break;

                     }

                     case AVAssetExportSessionStatusCompleted: {

                         NSLog (@"AVAssetExportSessionStatusCompleted");

                         [self uploadMusic:exportFile]; //这里上传

                         break;

                     }

                     case AVAssetExportSessionStatusUnknown: {

                         NSLog (@"AVAssetExportSessionStatusUnknown");

                         break;

                     }

                     case AVAssetExportSessionStatusExporting: {

                         NSLog (@"AVAssetExportSessionStatusExporting");

                         break;

                     }

                     case AVAssetExportSessionStatusCancelled: {

                         NSLog (@"AVAssetExportSessionStatusCancelled");

                         break;

                     }

                     case AVAssetExportSessionStatusWaiting: {

                         NSLog (@"AVAssetExportSessionStatusWaiting");

                         break;

                     }

                     default:

                     { NSLog (@"didn't get export status");

                         break;

                     }

                 }

             }];

        }else{

        }

    }

}


相关知识

韩网热议!Crush认证防弹少年团郑号锡咖啡厅“我们厚比生日快乐”阿米赠送宠物狗艺术
猫咪放松歌曲在线播放免费听
劲爆歌曲大全100首
我的老父亲歌曲原唱
久唱不衰的闽南语歌曲——从闽南语歌曲看台湾人的社会心理
《中国好歌曲第二季
宠物跳舞机热门歌曲推荐:狗狗专用舞曲精选集
上传文件和提交textfield
狗狗跳舞机热门歌曲列表及完整音乐名称汇总
小猫小狗窝里睡了什么歌曲

网址: itunes 歌曲导出 和上传 https://m.mcbbbk.com/newsview396711.html

所属分类:萌宠日常
上一篇: 为了英克雷而战
下一篇: 求教,宠物怎么快速升级,顺便说一