Commit c73939fa authored by chunsen's avatar chunsen

feat: 更新音频录制组件,支持更多音频格式上传并优化文件名处理逻辑

parent 91b24323
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
Record Audio Record Audio
</div> </div>
<nz-upload <nz-upload
[nzAccept] = "'.mp3'" [nzAccept] = "'.mp3,.m4a,.wav,.ogg'"
[nzShowUploadList]="false" [nzShowUploadList]="false"
[nzAction]="uploadUrl" [nzAction]="uploadUrl"
[nzData]="uploadData" [nzData]="uploadData"
......
...@@ -214,7 +214,10 @@ export class AudioRecorderComponent implements OnInit, OnChanges, OnDestroy { ...@@ -214,7 +214,10 @@ export class AudioRecorderComponent implements OnInit, OnChanges, OnDestroy {
case 'success': case 'success':
this.isUploading = false; this.isUploading = false;
let url = info.file.response.url; let url = info.file.response.url;
url = url.substring(0, url.lastIndexOf(".")) + "_l.mp3"; // 获取文件扩展名
const extension = url.substring(url.lastIndexOf("."));
// 保留原始文件格式,只添加_l前缀
url = url.substring(0, url.lastIndexOf(".")) + "_l" + extension;
info.file.response.url = url; info.file.response.url = url;
this.uploadSuccess(info.file.response); this.uploadSuccess(info.file.response);
this.audioUploaded.emit(info.file.response); this.audioUploaded.emit(info.file.response);
...@@ -229,9 +232,9 @@ export class AudioRecorderComponent implements OnInit, OnChanges, OnDestroy { ...@@ -229,9 +232,9 @@ export class AudioRecorderComponent implements OnInit, OnChanges, OnDestroy {
if (!file) { if (!file) {
return; return;
} }
const isAudio = ['audio/mp3', 'audio/wav', 'audio/ogg'].includes(file.type); const isAudio = ['audio/mp3', 'audio/wav', 'audio/ogg', 'audio/m4a', 'audio/x-m4a'].includes(file.type);
if (!isAudio) { if (!isAudio) {
this.nzMessageService.error('You can only upload Audio file ( mp3 | wav |ogg)'); this.nzMessageService.error('You can only upload Audio file ( mp3 | wav | ogg | m4a )');
return; return;
} }
const delta = 25; const delta = 25;
...@@ -277,7 +280,10 @@ export class AudioRecorderComponent implements OnInit, OnChanges, OnDestroy { ...@@ -277,7 +280,10 @@ export class AudioRecorderComponent implements OnInit, OnChanges, OnDestroy {
} }
linkInputed (url, name) { linkInputed (url, name) {
url = url.substring(0, url.lastIndexOf(".")) + "_l.mp3"; // 获取文件扩展名
const extension = url.substring(url.lastIndexOf("."));
// 保留原始文件格式,只添加_l前缀
url = url.substring(0, url.lastIndexOf(".")) + "_l" + extension;
this.audioUrl = url; this.audioUrl = url;
this.audioUploaded.emit({url}); this.audioUploaded.emit({url});
this.audioName.emit(name); this.audioName.emit(name);
...@@ -298,7 +304,7 @@ export class AudioRecorderComponent implements OnInit, OnChanges, OnDestroy { ...@@ -298,7 +304,7 @@ export class AudioRecorderComponent implements OnInit, OnChanges, OnDestroy {
if (url.indexOf("teach")<0 || url.indexOf("cdn")<0) { if (url.indexOf("teach")<0 || url.indexOf("cdn")<0) {
return; return;
} }
const white = [".mp3"]; const white = [".mp3", ".m4a"];
if (!white.includes(url.substr(url.lastIndexOf(".")))) { if (!white.includes(url.substr(url.lastIndexOf(".")))) {
return; return;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment