일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- nvm
- 커스텀알림
- 타입스크립트
- 구조분해할당
- leetcode977
- 백준
- yarn-berry
- iP
- youtube iframe
- Python
- Rest
- react-native
- 파이썬
- react-firebaseui
- Next.js
- 파이어베이스로그인
- 리액트
- nvmrc
- Spread
- 자바스크립트
- JS
- 기초
- React
- 프로토타입
- css
- leetcode189
- 커스텀알락
- 다리놓기
- mac
- firebaseui
- Today
- Total
JadeCode
[Next.js] 유튜브 불러오기 본문
프로젝트를 하던 중 유튜브 링크를 입력하고 불러와야하는 작업이 있었다.
처음에는 iframe을 사용하여 유튜브 링크를 넣었다.
src 에 유튜브 링크 주소를 그대로 넣었더니
이런 메세지가 떴다.
검색을 해 보니
"https://www.youtube.com/watch?v=????" 형태로 된 주소는 허용하지 않는 것이다.
해결 방법은 단순하다.
????부분은 영상의 ID로 그 ID를 토대로 불러오면 된다.
"http://www.youtube.com/embed/????" 형태로 src에 집어 넣으면 된다.
function extractVideoID(url: string) {
var regExp =
/^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
var match = url.match(regExp);
if (match && match[7].length == 11) {
return match[7];
} else {
alert("Could not extract video ID.");
}
}
// 위의 코드를 통해 유튜브 영상 아이디를 찾아내어 변수로 저장
return(
...
<iframe
src={`https://www.youtube.com/embed/${videoId}`}
allowFullScreen
/>
...)
https://developers.google.com/youtube/iframe_api_reference?hl=ko
iframe 삽입에 대한 YouTube Player API 참조 문서 | YouTube IFrame Player API | Google Developers
애플리케이션에 YouTube 플레이어를 삽입합니다.
developers.google.com
https://npmtrends.com/react-iframe-vs-react-player-vs-react-youtube-vs-video-react
react-iframe vs react-player vs react-youtube vs video-react | npm trends
Comparing trends for react-iframe 1.8.5 which has 85,982 weekly downloads and 392 GitHub stars vs. react-player 2.12.0 which has 696,703 weekly downloads and 7,523 GitHub stars vs. react-youtube 10.1.0 which has 262,710 weekly downloads and 1,675 GitHub st
npmtrends.com
https://www.labnol.org/code/19797-regex-youtube-id
RegEx - Extract Video ID from YouTube URLs - Digital Inspiration
Google Developer Expert, Google Cloud Champion
www.labnol.org
'개발 > 오류해결' 카테고리의 다른 글
네아로 로그인 시 발생한 오류 (0) | 2023.04.22 |
---|---|
mui button only uppercase (0) | 2022.09.28 |
[MAC] Pycharm git clone 후 실행 안될 때 (0) | 2022.04.10 |
[MAC] 포트 사용 확인 및 닫기 (0) | 2022.02.07 |
[MAC] 숨김파일 (.으로 시작되는 파일, 도트파일) 보이기 (0) | 2021.12.11 |