解决了语音上传到问题,接下来要解决下载播放问题

This commit is contained in:
joywayer
2025-06-15 12:36:47 +08:00
parent bba3ed1cb4
commit c11fc62bf1
513 changed files with 31197 additions and 2969 deletions

View File

@@ -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);
// URLJS
if (self->_bridge) {
[self->_bridge callHandler:@"recordSuccess" data:@{
@"fileUrl": fileUrl,
@"fileName": uniqueFileName,
@"fileKey": key
}];
}
}
});
}];
//
} else {
NSLog(@"AMR文件无效或为空");
}
@@ -2476,3 +2531,5 @@
}}
@end