@@ -18,6 +18,7 @@ import { Session } from "next-auth";
18
18
import stampIcon from "@/public/icons/stamp.png" ;
19
19
import PhotoUploader from "@/app/_components/PhotoUploader" ;
20
20
import { useSession } from "next-auth/react" ;
21
+ import YouTube , { YouTubeProps } from "react-youtube" ;
21
22
22
23
interface LocationImage {
23
24
id : number ;
@@ -47,6 +48,8 @@ export default function Page() {
47
48
</ div >
48
49
< div className = "w-full" >
49
50
< ImageCarousel images = { loc ?. images } />
51
+
52
+ < VideoInfo videoLink = { loc ?. video_link ?? "" } />
50
53
</ div >
51
54
< p className = "mb-6 self-start text-sm text-neutral-700" >
52
55
{ loc ?. description }
@@ -274,3 +277,50 @@ function ImageCarousel({ images }: { images: LocationImage[] | undefined }) {
274
277
</ Carousel >
275
278
) ;
276
279
}
280
+
281
+ function extractYoutubeId ( { videoLink } : { videoLink : string } ) {
282
+ try {
283
+ const url = new URL ( videoLink ) ;
284
+
285
+ // 1. 짧은 URL 형태 처리 (youtu.be)
286
+ if ( url . hostname === "youtu.be" ) {
287
+ return url . pathname . slice ( 1 ) ; // 첫 번째 슬래시 제거하고 ID 반환
288
+ }
289
+
290
+ // 2. 일반 URL 형태 처리 (www.youtube.com)
291
+ if ( url . hostname . includes ( "youtube.com" ) ) {
292
+ const urlParams = new URLSearchParams ( url . search ) ;
293
+ return urlParams . get ( "v" ) ;
294
+ }
295
+
296
+ return null ; // 유효하지 않은 YouTube URL
297
+ } catch ( error ) {
298
+ console . error ( "Invalid YouTube URL:" , videoLink , error ) ;
299
+ return null ;
300
+ }
301
+ }
302
+
303
+ function VideoInfo ( { videoLink } : { videoLink : string } ) {
304
+ //youtube id 추출
305
+ const youtubeId = videoLink ? extractYoutubeId ( { videoLink } ) : " " ;
306
+
307
+ console . log ( videoLink , youtubeId ) ;
308
+ const onPlayerReady : YouTubeProps [ "onReady" ] = ( event ) => {
309
+ // access to player in all event handlers via event.target
310
+ event . target . pauseVideo ( ) ;
311
+ } ;
312
+
313
+ const opts : YouTubeProps [ "opts" ] = {
314
+ height : "200" ,
315
+ width : "250" ,
316
+ playerVars : {
317
+ autoplay : 1 ,
318
+ } ,
319
+ } ;
320
+
321
+ return (
322
+ < div className = "mt-4 flex flex-col gap-5" >
323
+ < YouTube videoId = { youtubeId } opts = { opts } onPlayerReady = { onPlayerReady } />
324
+ </ div >
325
+ ) ;
326
+ }
0 commit comments