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

标签 iphone streaming asihttprequest

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

我尝试了很多次,也没有任何线索!!

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];

有什么想法吗?谢谢

最佳答案

好吧,经过挖掘和痛苦..我找到了一个简单的方法来做到这一点..

我将代码上传到 github-MOUploadAudioStreamer

希望它能对某人有所帮助..

关于iphone - 将音频从 iPhone 流式传输到服务器(HTTP 流式传输),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16582450/

相关文章:

iphone - UITableView 不尊重 heightForHeaderInSection/heightForFooterInSection?

java - 将大字节数组写入输出流可能产生的影响?

ios - XCode 找不到#import "ASIHTTPRequest.h"IOS 4.3

ios - ASIHTTPRequest 不更新进度

iphone - 在 iPhone 上播放 .flv 文件

iphone - 在 iOS 设备上显示像素光栅的最快方法

iphone - 平滑 Core Graphics 中的圆形笔划

c++ - 在 C++ 中检查文件是否存在、大小和相似性

streaming - 如何正确停止和终止 Twitter4j 流

ios - ASIHTTP请求委托(delegate)