Emuixom commited on
Commit
a780f3d
verified
1 Parent(s): 305b5eb

Create Repro.html

Browse files
Files changed (1) hide show
  1. Repro.html +84 -0
Repro.html ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Reproductor de M煤sica</title>
7
+ <style>
8
+ body {
9
+ font-family: Arial, sans-serif;
10
+ text-align: center;
11
+ }
12
+ #player {
13
+ width: 100%;
14
+ max-width: 600px;
15
+ height: 350px;
16
+ margin: 20px auto;
17
+ }
18
+ </style>
19
+ </head>
20
+ <body>
21
+
22
+ <h1>Reproductor de M煤sica desde YouTube</h1>
23
+ <input type="text" id="youtube-url" placeholder="Ingresa la URL de YouTube" style="width: 80%; padding: 10px;">
24
+ <button onclick="loadVideo()">Cargar Video</button>
25
+
26
+ <div id="player"></div>
27
+
28
+ <script>
29
+ // Cargar el iframe de YouTube de manera din谩mica
30
+ function onYouTubeIframeAPIReady() {
31
+ window.player = new YT.Player('player', {
32
+ height: '350',
33
+ width: '600',
34
+ videoId: '', // Inicialmente vac铆o
35
+ events: {
36
+ 'onReady': onPlayerReady,
37
+ 'onStateChange': onPlayerStateChange
38
+ }
39
+ });
40
+ }
41
+
42
+ // Cuando el reproductor est谩 listo
43
+ function onPlayerReady(event) {
44
+ console.log("Reproductor listo.");
45
+ }
46
+
47
+ // Detectar el estado del video (por ejemplo, si termin贸)
48
+ function onPlayerStateChange(event) {
49
+ if (event.data === YT.PlayerState.ENDED) {
50
+ console.log("El video termin贸.");
51
+ }
52
+ }
53
+
54
+ // Cargar un nuevo video usando la URL de YouTube
55
+ function loadVideo() {
56
+ var url = document.getElementById('youtube-url').value;
57
+ var videoId = extractVideoId(url);
58
+ if (videoId) {
59
+ player.loadVideoById(videoId);
60
+ } else {
61
+ alert('URL de YouTube no v谩lida');
62
+ }
63
+ }
64
+
65
+ // Extraer el video ID de una URL de YouTube
66
+ function extractVideoId(url) {
67
+ var videoId = '';
68
+ var regex = /(?:https?:\/\/(?:www\.)?youtube\.com\/(?:[^\/]+\/.*\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/;
69
+ var match = url.match(regex);
70
+ if (match) {
71
+ videoId = match[1];
72
+ }
73
+ return videoId;
74
+ }
75
+
76
+ // Cargar la API de YouTube
77
+ var tag = document.createElement('script');
78
+ tag.src = "https://www.youtube.com/iframe_api";
79
+ var firstScriptTag = document.getElementsByTagName('script')[0];
80
+ firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
81
+ </script>
82
+
83
+ </body>
84
+ </html>