File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change 77
77
{ key : 1.5 , text : '1.5x' } ,
78
78
{ key : 2 , text : '2x' } ,
79
79
] ,
80
+ audioMimeTypes = {
81
+ mp3 : 'audio/mpeg' ,
82
+ wav : 'audio/wav' ,
83
+ ogg : 'audio/ogg' ,
84
+ flac : 'audio/flac' ,
85
+ aac : 'audio/aac' ,
86
+ m4a : 'audio/mp4' ,
87
+ } ,
80
88
// Love ya Safari.
81
89
promisifyDecodeAudioData = ( audioContext : AudioContext , audioData : ArrayBuffer ) => new Promise < AudioBuffer > ( ( resolve , reject ) => {
82
90
audioContext . decodeAudioData ( audioData , resolve , reject )
@@ -125,9 +133,11 @@ export const XAudioAnnotator = ({ model }: { model: AudioAnnotator }) => {
125
133
setErrMsg ( 'Could not download audio file.' )
126
134
return
127
135
}
136
+ const ext = model . path . split ( '.' ) . pop ( ) ?. toLowerCase ( ) as keyof typeof audioMimeTypes
137
+ const type = audioMimeTypes [ ext ] || 'audio/mpeg'
128
138
// Store the URL into the ref so that it can be revoked on destroy and mem leak prevented.
129
139
// Safari needs Blob type to be specified, doesn't need to match the real sound format.
130
- fetchedAudioUrlRef . current = URL . createObjectURL ( new Blob ( [ arrBuffer ] , { type : 'audio/mpeg' } ) )
140
+ fetchedAudioUrlRef . current = URL . createObjectURL ( new Blob ( [ arrBuffer ] , { type } ) )
131
141
// Do not set src directly within HTML to prevent double fetching.
132
142
audioRef . current . src = fetchedAudioUrlRef . current
133
143
You can’t perform that action at this time.
0 commit comments