반응형
✔️ 에러 코드
Uncaught (in promise) DOMException: The element has no supported sources.
✔️ 에러가 나온 이유
오디오 파일이 로드 중 상태에서, 로드가 최적화되기 전 재생을 실행하는 것이 문제가 되는 것 같다. 😅
그래서 오디오 파일을 완전히 불러온 후 재생하도록 코드를 수정했다.
👇에러코드 👇
import React from "react";
const AudioPlayer = () => {
let audio = new Audio("../../assets/audio/train_horn.mp3");
const start = () => {
audio.play();
};
return (
<div>
<button onClick={start}>start</button>
</div>
);
};
export default AudioPlayer;
👇에러 수정 코드 👇
import React from "react";
import sound from "../../assets/audio/train_horn.mp3";
const AudioPlayer = () => {
let audio = new Audio(sound);
const start = () => {
audio.play();
};
return (
<div>
<button onClick={start}>start</button>
</div>
);
};
export default AudioPlayer;
참고
https://github.com/codingeverybody/codingyahac/issues/577
오디오를 재생하는 버튼에 문제가 발생합니다. · Issue #577 · codingeverybody/codingyahac
해결하고자 하는 문제 안녕하세요? 버튼을 터치하면 해당 변수의 오디오가 재생 되는 코드를 만들었습니다. 그런데 처음 페이지가 로드 되었을 때 다른 액션 없이 버튼을 가장 먼저 터치하면 'Un
github.com
DOMException: Failed to load because no supported source was found
I'm getting DOMException: Failed to load because no supported source was found in video.play(); line. I'm getting this issue only after adding video.setAttribute('crossorigin', 'anonymous'); I'm
stackoverflow.com
😃 잘못된 개념 전달이 있다면 댓글 부탁드립니다. 저의 성장에 큰 도움이 됩니다🤓
반응형
'❗️Error > 오류를 해결하자!' 카테고리의 다른 글
'replaceAll' 속성이 'string' 형식에 없습니다. ts(2550) (0) | 2023.10.15 |
---|---|
[React] Link로 데이터 전달하는 방법 (0) | 2023.01.09 |
서버 요청시 비동기 처리를 하지 않는다면? (0) | 2022.12.28 |
Uncaught TypeError: Cannot read properties of undefined (reading 'map'), 옵셔널 체이닝 (0) | 2022.12.27 |
vite에서 emotion css props 사용하기 (0) | 2022.12.13 |