解决了语音上传到问题,接下来要解决下载播放问题
This commit is contained in:
@@ -43,6 +43,8 @@
|
||||
#import <CommonCrypto/CommonDigest.h>
|
||||
#import <AdSupport/ASIdentifierManager.h>
|
||||
#import "XianliaoApiManager.h"
|
||||
#import "QiniuManager.h"
|
||||
#import "QiniuConfig.h"
|
||||
@interface gameController ()
|
||||
<WKNavigationDelegate,WXApiManagerDelegate,VoiceRecorderBaseVCDelegate,AVAudioPlayerDelegate,ASIHTTPRequestDelegate,AMapLocationManagerDelegate,UIActionSheetDelegate,AgoraRtcEngineDelegate>
|
||||
{
|
||||
@@ -844,7 +846,7 @@
|
||||
CTTelephonyNetworkInfo *telephonyInfo = [[CTTelephonyNetworkInfo alloc] init];
|
||||
CTCarrier *carrier = [telephonyInfo subscriberCellularProvider];
|
||||
NSString *currentCountry=[carrier carrierName];
|
||||
// NSLog(@"[carrier isoCountryCode]==%@,[carrier allowsVOIP]=%d,[carrier mobileCountryCode=%@,[carrier mobileCountryCode]=%@",[carrier isoCountryCode],[carrier allowsVOIP],[carrier mobileCountryCode],[carrier mobileNetworkCode]);
|
||||
// NSLog(@"[carrier isoCountryCode]==%@,[carrier allowsVOIP]=%d,[carrier mobileCountryCode=%@,[carrier mobileNetworkCode]=%@",[carrier isoCountryCode],[carrier allowsVOIP],[carrier mobileCountryCode],[carrier mobileNetworkCode]);
|
||||
UIDevice *device = [[UIDevice alloc] init];
|
||||
// NSString *name = device.name; //获取设备所有者的名称
|
||||
NSString *model = device.model; //获取设备的类别
|
||||
@@ -2194,6 +2196,15 @@
|
||||
NSLog(@"录音时长过短,可能无效: %.2f秒", interval);
|
||||
return;
|
||||
}
|
||||
|
||||
//4.播放
|
||||
if (play == nil)
|
||||
{
|
||||
NSLog(@"ERror creating player: %@", [play description]);
|
||||
}else{
|
||||
[play play];
|
||||
}
|
||||
|
||||
|
||||
NSString *amrPath = [FuncPublic GetPathByFileName:_fileName ofType:@"amr"];
|
||||
NSLog(@"尝试转换WAV到AMR,源文件: %@,目标文件: %@", _filePath, amrPath);
|
||||
@@ -2223,23 +2234,67 @@
|
||||
NSLog(@"转换WAV到AMR成功");
|
||||
NSData *amrData = [NSData dataWithContentsOfFile:amrPath];
|
||||
if (amrData && amrData.length > 0) {
|
||||
// 数据有效,继续上传流程
|
||||
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
|
||||
//接收类型不一致请替换一致text/html或别的
|
||||
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",
|
||||
@"text/html",
|
||||
@"image/jpeg",
|
||||
@"image/png",
|
||||
@"application/octet-stream",
|
||||
@"text/json",
|
||||
@"audio/amr",
|
||||
nil];
|
||||
NSString *string=@"http://gameapi.0791ts.cn/api/UpLoad/PostFile";
|
||||
|
||||
|
||||
|
||||
|
||||
// 数据有效,使用QiniuManager上传到七牛云
|
||||
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
|
||||
formatter.dateFormat =@"yyyyMMddHHmmss";
|
||||
NSString *str = [formatter stringFromDate:[NSDate date]];
|
||||
NSString *fileName = [NSString stringWithFormat:@"%@%08X.amr", str, arc4random()];
|
||||
// 继续原有的上传逻辑...
|
||||
formatter.dateFormat = @"yyyyMMddHHmmss";
|
||||
NSString *timeStr = [formatter stringFromDate:[NSDate date]];
|
||||
NSString *uniqueFileName = [NSString stringWithFormat:@"%@_%08X.amr", timeStr, arc4random()];
|
||||
|
||||
// 显示上传状态提示
|
||||
// UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示"
|
||||
// message:@"正在上传录音文件..."
|
||||
// preferredStyle:UIAlertControllerStyleAlert];
|
||||
// [self presentViewController:alertController animated:YES completion:nil];
|
||||
|
||||
// 调用七牛云管理器上传文件
|
||||
[[QiniuManager sharedManager] uploadAudioFile:amrPath
|
||||
fileName:uniqueFileName
|
||||
progressHandler:^(float progress) {
|
||||
// 更新上传进度提示
|
||||
// dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// alertController.message = [NSString stringWithFormat:@"正在上传录音文件... %.0f%%", progress * 100];
|
||||
// });
|
||||
}
|
||||
completionHandler:^(NSString *key, NSError *error) {
|
||||
// 关闭上传进度提示
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// [alertController dismissViewControllerAnimated:YES completion:nil];
|
||||
|
||||
if (error) {
|
||||
// 上传失败处理
|
||||
// UIAlertController *errorAlert = [UIAlertController alertControllerWithTitle:@"上传失败"
|
||||
// message:error.localizedDescription
|
||||
// preferredStyle:UIAlertControllerStyleAlert];
|
||||
// UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
|
||||
// [errorAlert addAction:okAction];
|
||||
// [self presentViewController:errorAlert animated:YES completion:nil];
|
||||
//
|
||||
NSLog(@"七牛云上传失败: %@", error);
|
||||
} else {
|
||||
// 上传成功,获取文件URL
|
||||
NSString *fileUrl = [[QiniuManager sharedManager] getFileUrlWithKey:key];
|
||||
NSString *audiourl=[NSString stringWithFormat:@"%@/%@",kQiniuDomain,uniqueFileName];
|
||||
[_bridge callHandler:@"getaudiourl" data:@{ @"audiourl":audiourl,@"time":[NSString stringWithFormat:@"%ld",(long)time]} ];
|
||||
NSLog(@"七牛云上传成功,文件URL: %@", fileUrl);
|
||||
|
||||
// 将录音文件URL传递给JS接口
|
||||
if (self->_bridge) {
|
||||
[self->_bridge callHandler:@"recordSuccess" data:@{
|
||||
@"fileUrl": fileUrl,
|
||||
@"fileName": uniqueFileName,
|
||||
@"fileKey": key
|
||||
}];
|
||||
}
|
||||
}
|
||||
});
|
||||
}];
|
||||
|
||||
// 原有的上传流程代码注释掉或删除
|
||||
|
||||
} else {
|
||||
NSLog(@"AMR文件无效或为空");
|
||||
}
|
||||
@@ -2476,3 +2531,5 @@
|
||||
}}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user