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 Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

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