【问题标题】:streaming audio from iphone to server (HTTP streaming )将音频从 iphone 流式传输到服务器(HTTP 流式传输)
【发布时间】:2013-05-11 01:15:03
【问题描述】:

我使用下面的代码将音频文件从磁盘上传到服务器。 我想将文件作为流直接从 iphone mic 上传到服务器.. 使用 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];

有什么想法吗?!谢谢

【问题讨论】:

    标签: iphone streaming asihttprequest


    【解决方案1】:

    好吧,在挖掘和受苦之后..我找到了一个简单的方法来做到这一点..

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

    希望它毕竟对某人有所帮助..

    【讨论】:

      【解决方案2】:

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

      更多细节你可以试试苹果自己提供的Rosywriter。从这里你会得到详细的想法。

      在这里查看Rosywriter

      享受编程!

      【讨论】:

      • 我已经在使用 ASI.. 任何示例代码或对我的代码进行编辑将不胜感激..
      猜你喜欢
      • 2010-09-27
      • 2012-01-22
      • 1970-01-01
      • 1970-01-01
      • 2012-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-02
      相关资源
      最近更新 更多