jichoi / lms_front star
홍아랑 홍아랑 2024-08-14
240814 홍아랑 지문 영상 출력 로직 추가
@72ee90d5cecb6a9815e1d5f2f933ca0bea5872fb
client/views/pages/main/Chapter/Chapter1.vue
--- client/views/pages/main/Chapter/Chapter1.vue
+++ client/views/pages/main/Chapter/Chapter1.vue
@@ -14,40 +14,80 @@
             <div class="content title-box">
                 <p class="title mt25 title-bg">step1. Hello WORLD</p>
                 <div class="videoCon">
-                    <img src="../../../../resources/img/img34_s.png" data-num="1">
-                    <button class="videoStart" data-video="1" tabindex="0" aria-label="동영상 재생"><img src="../../../../resources/img/btn09_s.png"
-                            data-num="1"></button>
-                           <div class="look-text"> <button ><img src="../../../../resources/img/btn08_s.png" alt=""><p>지문 보기</p></button></div>
+                    <div ref="youtubePlayer" class="youtube-player"></div>
                 </div>
             </div>
-            <div class="next-btn"  @click="goToPage('Chapter1_1')"><img src="../../../../resources/img/right.png" alt=""></div>
+            <div class="next-btn" @click="goToPage('Chapter1_2')"><img src="../../../../resources/img/right.png" alt=""></div>
         </div>
-        <TextToImage/>
+        <TextToImage />
     </div>
 </template>
 
 <script>
 import TextToImage from '../../../component/TextToImage.vue';
+
 export default {
-    data() {
-        return {
-        }
+    components: {
+        TextToImage
     },
     methods: {
         goToPage(page) {
             this.$router.push({ name: page });
+        },
+        loadYouTubeAPI() {
+            return new Promise((resolve, reject) => {
+                if (window.YT && window.YT.Player) {
+                    resolve(); // API가 이미 로드된 경우
+                } else {
+                    const script = document.createElement('script');
+                    script.src = 'https://www.youtube.com/iframe_api';
+                    script.onload = () => {
+                        // 스크립트가 로드되면, `YT` 객체가 준비될 때까지 기다립니다.
+                        const checkYTReady = setInterval(() => {
+                            if (window.YT && window.YT.Player) {
+                                clearInterval(checkYTReady);
+                                resolve();
+                            }
+                        }, 100); // 100ms마다 `YT` 객체가 준비되었는지 확인
+                    };
+                    script.onerror = () => reject(new Error('Failed to load the YouTube API script'));
+                    document.body.appendChild(script);
+                }
+            });
+        },
+        initializePlayer() {
+            if (!window.YT || !window.YT.Player) {
+                console.error('YouTube Player is not available');
+                return;
+            }
+            new window.YT.Player(this.$refs.youtubePlayer, {
+                height: '550',
+                width: '950',
+                videoId: 'VloEiK4Ihj8', // 비디오 ID
+                events: {
+                    'onReady': this.onPlayerReady
+                }
+            });
+        },
+        onPlayerReady(event) {
+            event.target.playVideo(); // 비디오가 준비되면 자동 재생
         }
     },
-    watch: {
-
-    },
-    computed: {
-
-    },
-    components: {
-        TextToImage : TextToImage,
-    },
     mounted() {
+        this.loadYouTubeAPI()
+            .then(() => {
+                this.initializePlayer();
+            })
+            .catch(error => {
+                console.error('Error loading YouTube API:', error);
+            });
     }
 }
-</script>
(No newline at end of file)
+</script>
+
+<style scoped>
+.youtube-player {
+    width: 950px; /* 플레이어의 가로 크기 */
+    height: 550px; /* 플레이어의 세로 크기 */
+}
+</style>
Add a comment
List