cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <video id="video-js" class="video-js" controls="controls">
    <source type="video/mp4" src="//download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_320x180.mp4" type="video/mp4" />
</video>
<audio id="audiodescription" preload="auto">
    <source src="//sampleswap.org/mp3/artist/8669/canton_Indian-Summer2-160.mp3" type="audio/mp3" />
</audio>
            
          
!
            
              var video = document.getElementById('video-js');
//on inialise le player
videojs('video-js', {}, function() {
		//on défini la différence entre les deux volumes
		var ratioVolume = 0.3;
    //on verifie si il y a bien un fichier d'audio-description
    var audioDescription = document.getElementById('audiodescription');
    if ( audioDescription ) {
        //on ajoute le bouton
        //(this = le player videojs)
        var ADButton = this.controlBar.addChild('button');
        ADButton.el_.classList.add('vjs-icon-audio-description');

        //on redéfini les volumes
        audioDescription.volume = 0;
        this.volume( ratioVolume );
        
        //toggle sur le bouton pour "mute" l'audio-description ou non
        ADButton.on('click', function( e ) {
        		if( audioDescription.volume ){
            		audioDescription.volume = 0;
            } else {
            		audioDescription.volume = Math.min( video.volume + ratioVolume , 1);
            }
        });
      
      console.info(audioDescription.volume);

        //play de la video => play sur l'AD
        this.on('play', function() {
            if ( audioDescription.paused ) {
                audioDescription.play();
            }
        });

        //pour sur la video => pause sur l'AD
        this.on('pause', function() {
            if ( !audioDescription.paused ) {
                audioDescription.pause();
            }
        });

        //fin de la video => pause sur l'AD
        this.on('ended', function() {
            this.pause();
            audioDescription.pause();
        });
      
        //synchro sur le volume
        this.on('volumechange', function() {
          if( audioDescription.volume ) {
            audioDescription.volume = Math.min( video.volume + ratioVolume , 1);
          }
        });
      
        //synchro sur le seek
        this.on('timeupdate', function() {
            if ( audioDescription.readyState >= 4 ) {
                if( Math.ceil(audioDescription.currentTime) != Math.ceil(this.currentTime()) ) {
                    audioDescription.currentTime = this.currentTime();
                }
            }
        });
    }
});
            
          
!
999px
Loading ..................

Console