IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JavaScript Discussion :

PlayVideo() ne marche pas


Sujet :

JavaScript

  1. #1
    Invité
    Invité(e)
    Par défaut PlayVideo() ne marche pas
    Bonjour, j'essaie de lancer une vidéo Youtube avec Javascript mais ça ne marche pas.

    Code HTML : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    <!DOCTYPE html>
    <html>
     
      <head></head>
     
      <body>
        <!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
        <div id="player"></div>
     
        <script>
          // 2. This code loads the IFrame Player API code asynchronously.
          var tag = document.createElement('script');
     
          tag.src = "https://www.youtube.com/player_api";
          var firstScriptTag = document.getElementsByTagName('script')[0];
          firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
     
          // 3. This function creates an <iframe> (and YouTube player)
          //    after the API code downloads.
          var player;
          function onYouTubeIframeAPIReady() {
            player = new YT.Player('player', {
              height: '360',
              width: '640',
              videoId: 'k4jI_63l3sM',
              events: {
                'onReady': onPlayerReady,
              }
            });
          }
     
          // 4. The API will call this function when the video player is ready.
          function onPlayerReady(event) {
            player.playVideo();
          }
     
        </script>
     
      </body>
    </html>
    Dernière modification par ProgElecT ; 21/04/2019 à 18h42. Motif: Bienvenue sur DVP, s'il vous plait, autant que possible, indiquer le langage utilisé, [CODE=xyz], pour activer la bonne coloration syntaxique.

  2. #2
    Rédacteur

    Avatar de danielhagnoul
    Homme Profil pro
    Étudiant perpétuel
    Inscrit en
    Février 2009
    Messages
    6 389
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 74
    Localisation : Belgique

    Informations professionnelles :
    Activité : Étudiant perpétuel
    Secteur : Enseignement

    Informations forums :
    Inscription : Février 2009
    Messages : 6 389
    Billets dans le blog
    125
    Par défaut


    Je viens de tester ce code dans ma page de test, sur Chrome, et cela fonctionne :

    Code HTML : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    <!DOCTYPE html>
    <html lang="fr" dir="ltr">
     
    <head>
        <!-- cache-control avec max-age=60 pour le développement uniquement -->
        <meta http-equiv="cache-control" content="public, max-age=60">
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
    </head>
     
    <body>
     
        <main>
            <!-- code du test -->
     
            <!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
            <div id="player"></div>
     
            <script>
                // 2. This code loads the IFrame Player API code asynchronously.
                let tag = document.createElement('script');
     
                tag.src = "https://www.youtube.com/player_api";
     
                let firstScriptTag = document.getElementsByTagName('script')[0];
     
                firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
     
                // 3. This function creates an <iframe> (and YouTube player)
                //    after the API code downloads.
                let player;
     
                function onYouTubeIframeAPIReady() {
                    player = new YT.Player('player', {
                        height: '360',
                        width: '640',
                        videoId: 'k4jI_63l3sM',
                        events: {
                            'onReady': onPlayerReady,
                        }
                    });
                }
     
                // 4. The API will call this function when the video player is ready.
                function onPlayerReady(event) {
                    player.playVideo();
                }
            </script>
     
            <!-- fin code du test -->
        </main>
     
    </body>
     
    </html>

    Blog

    Sans l'analyse et la conception, la programmation est l'art d'ajouter des bogues à un fichier texte vide.
    (Louis Srygley : Without requirements or design, programming is the art of adding bugs to an empty text file.)

  3. #3
    Invité
    Invité(e)
    Par défaut
    Chez moi ça ne marche ni sur Chrome ni sur Firefox
    La vidéo semble se lancer puis s'arrête immédiatement. D'où peut venir le problème ?

Discussions similaires

  1. 'SHOW TABLES' marche pas sous postgresql !?
    Par fet dans le forum PostgreSQL
    Réponses: 4
    Dernier message: 13/05/2004, 09h28
  2. Maximiser fenêtre ne marche pas
    Par sandrinec dans le forum Composants VCL
    Réponses: 2
    Dernier message: 12/06/2003, 12h02
  3. Réponses: 9
    Dernier message: 07/05/2003, 12h57
  4. [GifDecoder] marche pas dans applet avec IE
    Par formentor dans le forum Applets
    Réponses: 2
    Dernier message: 06/05/2003, 10h43
  5. Sysdate qui marche pas ??
    Par StouffR dans le forum Langage SQL
    Réponses: 4
    Dernier message: 28/08/2002, 13h23

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo