Play audio from beginning

 How can I play audio(video) from beginning when I change slide.Thanks

falcon's picture

You mean via a setting, or as an end user? There are no settings for this, so you would have to code it. The end user may achieve it by dragging the seek bar.

I use a similar code for the video. ( Flexslider + videojs).

How can I implement something similar in H5P?



Drupal.behaviors.my_custom2_flexslider_behaviour = {
        attach: function (context, settings) {  
          $('#slidem').bind('after', function(e, slider) {
              var currentVidID;
             currentVidID = $('#slidem .flex-active-slide video').attr('id');
             if (currentVidID ){
             myPlayer = videojs(currentVidID); // Setting to the currently viewed player. We might not be on the first video when this is called.
                     //var player = currentVidID;
                    //$f(player).addEvent('ready', ready);
                    if (myPlayer.duration() > 0){
                        //myPlayer.addEvent('ended',  resumeslider()       );
                console.log('Video Complete');





falcon's picture

The suggestions below are not complete and have not been tested. They're just written to you as pointers on how you might try to achieve what you want.

For interactive video inside Flexslider you could try...

Inside the $('#slidem').bind('after', function(e, slider) { block you could try to add something like:

// If an H5P iframe exists we look there, if not it should be in our window
var instances = jQuery('.h5p-iframe').length > 0 ? jQuery('.h5p-iframe')[0].contentWindow.H5P.instances : H5P.instances;
// Find the instance and get the score from it if possible
for (var i = 0; i < instances.length; i++) {
  if (typeof instances[i].seek === 'function') {

For Audio inside CP it would be something like this:

H5P.externalDispatcher.on('xAPI', function(event) {
  if (event.getVerb() === 'progressed') {
    // Get the H5P content id for the question
    var contentId = event.getVerifiedStatementValue(['object', 'definition', 'extensions', '']);
    // If an H5P iframe exists we look there, if not it should be in our window
    var instances = $('.h5p-iframe').length > 0 ? $('.h5p-iframe')[0].contentWindow.H5P.instances : H5P.instances;
    // Find the instance and search for an Audio instance
    for (var i = 0; i < instances.length; i++) {
      if (instances[i].contentId === contentId) {
        var cp = instances[i];
        var slideInstances = cp.elementInstances[cp.currentSlideIndex];
        if (slideInstances !== undefined) {
        for (var i = 0; i < slideInstances.length; i++) {
          if (!cp.slides[cp.currentSlideIndex].elements[i].displayAsButton) {
            // Only play audio displayed as poster
            if (slideInstances[i].audio) {
              slideInstances[i].audio.currentTime = 0;