Commit b68f5171 authored by chunsen's avatar chunsen

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

parent c73939fa
...@@ -214,10 +214,8 @@ export class AudioRecorderComponent implements OnInit, OnChanges, OnDestroy { ...@@ -214,10 +214,8 @@ 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;
// 获取文件扩展名
const extension = url.substring(url.lastIndexOf("."));
// 保留原始文件格式,只添加_l前缀 // 保留原始文件格式,只添加_l前缀
url = url.substring(0, url.lastIndexOf(".")) + "_l" + extension; url = this.replaceAudioUrl(url);
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);
...@@ -228,6 +226,13 @@ export class AudioRecorderComponent implements OnInit, OnChanges, OnDestroy { ...@@ -228,6 +226,13 @@ export class AudioRecorderComponent implements OnInit, OnChanges, OnDestroy {
break; break;
} }
} }
replaceAudioUrl(url: string) {
const ext = url.substring(url.lastIndexOf(".")).toLowerCase();
if(ext === ".mp3") {
url = url.substring(0, url.lastIndexOf(".")) + "_l.mp3";
}
return url;
}
checkSelectFile(file: any) { checkSelectFile(file: any) {
if (!file) { if (!file) {
return; return;
...@@ -280,10 +285,8 @@ export class AudioRecorderComponent implements OnInit, OnChanges, OnDestroy { ...@@ -280,10 +285,8 @@ export class AudioRecorderComponent implements OnInit, OnChanges, OnDestroy {
} }
linkInputed (url, name) { linkInputed (url, name) {
// 获取文件扩展名
const extension = url.substring(url.lastIndexOf(".")); url = this.replaceAudioUrl(url);
// 保留原始文件格式,只添加_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);
...@@ -304,7 +307,7 @@ export class AudioRecorderComponent implements OnInit, OnChanges, OnDestroy { ...@@ -304,7 +307,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", ".m4a"]; const white = [".mp3", ".m4a", ".wav", ".ogg"];
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