gpt4 book ai didi

iphone - 如何将ios音频上传到服务器?

转载 作者:行者123 更新时间:2023-12-03 02:34:27 25 4
gpt4 key购买 nike

我试图将音频文件上传到服务器。而且我在列表音频中使用了MPMedia Picker View ,当我选择要上传到服务器(http)的音频时,该如何做。任何人都可以提供任何示例教程或示例代码。

我试过下面的代码。

- (IBAction)openMediaPicker:(id)sender {
MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeMusic];
mediaPicker.delegate = self;
mediaPicker.allowsPickingMultipleItems = YES; // this is the default
[self presentModalViewController:mediaPicker animated:YES];
[mediaPicker release];
}

- (IBAction)volumeSliderChanged:(id)sender {
self.musicPlayer.volume = self.volumeSlider.value;
}

#pragma mark MPMediaPickerController delegate methods

- (void)mediaPicker: (MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection {
// We need to dismiss the picker
[self dismissModalViewControllerAnimated:YES];

// Assign the selected item(s) to the music player and start playback.
[self.musicPlayer stop];
[self.musicPlayer setQueueWithItemCollection:mediaItemCollection];
[self.musicPlayer play];
}

- (void)mediaPickerDidCancel:(MPMediaPickerController *)mediaPicker {
// User did not select anything
// We need to dismiss the picker
[self dismissModalViewControllerAnimated:YES];
}

最佳答案

从mediaItemCollection.items数组的某些索引初始化MPMediaItem对象:

MPMediaItem * anItem =(MPMediaItem *)[mediaItemCollection.items objectAtIndex:row];

然后调用-valueForProperty:方法:

NSURL * assetURL = [anItem valueForProperty:MPMediaItemPropertyAssetURL];

您还可以从此处描述的MPMediaItem获得其他属性:http://developer.apple.com/library/ios/#DOCUMENTATION/MediaPlayer/Reference/MPMediaItem_ClassReference/Reference/Reference.html

在“常规媒体项目属性键”下查看

希望这可以帮助!塔姆斯

使用ASIHTTPRequest上传如下所示的音频文件,

NSURL *audiourl = [NSURL URLWithString:@"Your Url"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:audiourl];
NSData *postData = [NSData dataWithContentsOfURL:SoundPath];
//SoundPath is your audio url path of NSDocumentDirectory.
[request addData:postData withFileName:@"myAudio.caf" andContentType:@"audio/caf" forKey:@"company_audio"];
[request setDelegate:self];
[request startSynchronous];

这样,您可以轻松地在服务器上上传音频文件。

关于iphone - 如何将ios音频上传到服务器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15157703/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com