fix: wav format audio, #2317
This commit is contained in:
+4
-2
@@ -28,12 +28,14 @@ export const convertFileSize = (
|
||||
): string | number => {
|
||||
if (!sizeInBytes) return allowEmpty ? '' : 0;
|
||||
|
||||
const fmt = 1024;
|
||||
|
||||
const units = ['B', 'KiB', 'MiB', 'GiB', 'TiB'];
|
||||
let size = sizeInBytes;
|
||||
let unitIndex = 0;
|
||||
|
||||
while (size >= 1024 && unitIndex < units.length - 1) {
|
||||
size /= 1024;
|
||||
while (size >= fmt && unitIndex < units.length - 1) {
|
||||
size /= fmt;
|
||||
unitIndex++;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
import { message } from 'antd';
|
||||
import { convertFileSize } from './index';
|
||||
|
||||
export const audioTypeMap: Record<string, string> = {
|
||||
'audio/wav': 'wav',
|
||||
'audio/mp3': 'mp3',
|
||||
'audio/mpeg': 'mp3',
|
||||
'audio/x-wav': 'wav'
|
||||
};
|
||||
|
||||
export const convertFileToBase64 = (file: File): Promise<string> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
@@ -42,6 +50,12 @@ export const loadAudioData = async (
|
||||
audio.addEventListener('ended', () => {
|
||||
URL.revokeObjectURL(audio.src);
|
||||
});
|
||||
|
||||
audio.addEventListener('error', () => {
|
||||
URL.revokeObjectURL(url);
|
||||
message.error('Failed to load audio metadata invalid file');
|
||||
reject(new Error('Failed to load audio metadata invalid file'));
|
||||
});
|
||||
} catch (error) {
|
||||
console.log('error====', error);
|
||||
reject(error);
|
||||
|
||||
Reference in New Issue
Block a user