是否可以像在我的 iOS 应用程序中访问图像库一样访问声音文件库,我尝试在网上搜索但没有找到任何关于它的好内容。
问问题
723 次
2 回答
1
您可以参考 Apple 的AddMusic示例应用程序,了解它是如何完成的...
于 2012-06-21T11:45:36.290 回答
0
是的,您可以将其上传到服务器。使用以下代码:
当您从选取器中选择一首歌曲时
- (void)mediaPicker: (MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection
{
MPMediaItem *song = nil ;
[self dismissModalViewControllerAnimated:YES];
if ([mediaItemCollection count] < 1)
{
return;
}
[song release];
song = [[[mediaItemCollection items] objectAtIndex:0] retain];
//song.accessibilityHin
[self uploadMusicFile:song];
}
- (void) uploadMusicFile:(MPMediaItem *)song
{
// Init audio with playback capability
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];
NSURL *assetURL = [song valueForProperty:MPMediaItemPropertyAssetURL];
AVURLAsset *songAsset = [AVURLAsset URLAssetWithURL:assetURL options:nil];
// to get uniqe time interval
[[NSDate date] timeIntervalSince1970];
// convert this ti string
NSTimeInterval seconds = [[NSDate date] timeIntervalSince1970];
NSString *intervalSeconds = [NSString stringWithFormat:@"%0.0f",seconds];
AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset: songAsset presetName: AVAssetExportPresetPassthrough];
exporter.outputFileType = @"public.mpeg-4";
NSString *exportFile = [[NSString alloc] initWithString:[DOCUMENTS_FOLDER stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.mp4",intervalSeconds]]];
NSURL *exportURL = [[NSURL fileURLWithPath:exportFile] retain];
exporter.outputURL = exportURL;
[exporter exportAsynchronouslyWithCompletionHandler:
^{
NSData *data = [NSData dataWithContentsOfURL:exportURL];
// Here your upload code
}];
}
于 2012-06-21T12:23:47.947 回答