首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将音频从iphone流式传输到服务器(HTTP流式传输)

将音频从iphone流式传输到服务器(HTTP流式传输)
EN

Stack Overflow用户
提问于 2013-05-16 16:26:11
回答 2查看 1.3K关注 0票数 2

我使用下面的代码将音频文件从磁盘上传到服务器。我想将文件作为流直接从iphone麦克风上传到服务器。使用speakHere示例,我们可以在录制时捕获音频包。

我试了很多次,都没有找到任何线索!

代码语言:javascript
复制
NSString *fullPathToFile = [recordedAudioFilesDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%i%i.wav",1,2 ]];


//..REMARK ,,change ayah froma nd ayah to and SurahID

 NSURL *url = [NSURL URLWithString:[NSString stringWithFormat: WEB_SERVICE_ADDRESS] ];




requestGlob = [[ASIHTTPRequest alloc] initWithURL:url]  ;
requestGlob.tag=[[NSString stringWithFormat:@"1000%i",1] intValue];
requestGlob.delegate=self;


[requestGlob setTimeOutSeconds:50];
[requestGlob setRequestMethod:@"PUT"];
[requestGlob setShouldContinueWhenAppEntersBackground:YES];
[requestGlob setShouldStreamPostDataFromDisk:NO];
[requestGlob setUseCookiePersistence:NO];
[requestGlob setUseSessionPersistence:NO];
[requestGlob setUseKeychainPersistence:NO];
[requestGlob setUploadProgressDelegate:self];



NSString *userName =@"f@ola.com";

NSLog(@"username is %@",userName);
//hashed md5 password//e10adc3949ba59abbe56e057f20f883e
NSString *passowrd =@"q";
//NSLog(@"password is %@",passowrd);
 NSData *authData1 = [userName dataUsingEncoding:NSASCIIStringEncoding];
//encoded username

NSString *encodedUsername = [NSString stringWithString: [authData1 base64Encoding]];
//username + : + password

NSString *combined =[NSString stringWithFormat:@"%@:%@",  encodedUsername,passowrd ];
//encoded combined

NSString *encodedEveryThing= [NSString stringWithString:[[combined dataUsingEncoding:NSUTF8StringEncoding] base64Encoding]];
//the most important line since username and password are not arguments and its embedded in the header of the html

[requestGlob addRequestHeader:@"Authorization" value:[NSString stringWithFormat:@"Basic %@",encodedEveryThing]];




 [requestGlob appendPostDataFromFile:fullPathToFile];

[requestGlob startAsynchronous];

有什么想法吗?!thnx

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-06-30 21:53:41

经过挖掘和磨难之后..。我找到了一个简单的方法来做到这一点。

我把我的代码上传到了github-MOUploadAudioStreamer

希望它最终能帮助到某些人..

票数 2
EN

Stack Overflow用户

发布于 2013-05-16 16:37:17

我建议你使用ASIHTTPRequest库。它可以直接从手机上传文件,而不是先将文件加载到内存中。

对于更多的细节,你可以尝试由苹果itself.From提供的Rosywriter,这将使你得到详细的想法。

在这里看一下Rosywriter

享受编程吧!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16582450

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档