HTML5 audio play event not firing.

Workarounds and usability notes.

HTML5 audio play event not firing.

Postby John Robin Dove » Tue May 29, 2018 7:22 am

Hi Clifton,

I don't think this has anything to do with Powerpac. Below is part of the code I use for making, playing and uploading audio files.

Code: Select all
function endFile(blob, extension) {

      if (extension == "wav") {
       if (mySilent == false)
          {
          var url = URL.createObjectURL(blob); 
          var au = document.getElementById('myPlayer')       
          au.src = url;
          au.play();
          au.addEventListener('play',function(){
          top.tbfunction_pgTBObjSet("pleaseWait","trigger");
          });
          au.addEventListener('ended',function(){
          top.tbfunction_pgTBObjSet("ML1","trigger");
          });
          }

      } else {
        theBlob = blob;
        top.tbfunction_pgTBObjSet("ML4","trigger");
      }
    }
  };


I have been using this for about three years now and until a couple of days ago it had always worked. The user makes a recording which is then played. I use the play event to trigger code in an object in the DHTML. It now seems that play is no longer being fired. Strangely this is the case with one part of the program but not others! I have tried triggering another object but this makes no difference. The problem seems to be in the audio object. Why would this suddenly cease to function? Fortunately it is not a catastrophe because the timeupdate event serves my purpose equally well but I find these mysterious changes worrying. Just because something works once doesn't mean that it will always work. Any ideas?

John
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: HTML5 audio play event not firing.

Postby Clifton » Tue May 29, 2018 11:41 am

It looks like you are assigning your event listener AFTER the play() has been issued.
Try reversing these lines. Create your event listeners FIRST, that fire the play() event.
Your code cannot listen to something that already happened.

Just an initial observation.
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Re: HTML5 audio play event not firing.

Postby John Robin Dove » Wed May 30, 2018 2:22 am

Thanks for your reply. Your suggestion is very logical and I expected it to work but it didn't. Even stranger is the fact that if I put a timeupdate event listener before the play method that also fails to fire. One thing I forgot, due to ongoing senility, is the fact that the code that always worked over the last three years was slightly different. Instead of using the play method the audio's autoplay property was set to true and, if I remember correctly, this came before the addition of the event listeners. A month or two ago the autoplay property stopped working on Firefox (it still works with Chrome) so I replaced it with the play method and I put this in the same place as the autoplay = true line.
Anyway I'll stick with the timeupdate event listener as this appears to do what I want. I just hope that this does not decide to stop working.
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: HTML5 audio play event not firing.

Postby Clifton » Wed May 30, 2018 7:15 am

Please note that autoplay will continue to be a declining feature for developers to use. The advertising world is basically killing this feature and browsers are being designed to keep the web a pleasant experience for the majority. In addition, it is almost assured that if there is an audio channel, it will initially play muted. More and more developers are providing audio playback controls or at least a play button to start the audio.

Just curious, but have you tried to use the PowerPac html5 audio/video players in your scenario? If your audio or video is playing in the same frame or the parent window of the ToolBook frame, then you can leverage the player. Maybe that won't work in your scenario, but thought I would offer the suggestion. If you are using a pop up window to play your video/audio, then the browser may behave a bit more suspiciously as to what it allows until it detects some user interaction that determines that the user expected the new window to open.
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Re: HTML5 audio play event not firing.

Postby John Robin Dove » Thu May 31, 2018 3:38 am

Hi Clifton,
I am well aware of the autoplay situation. At the moment it seems to depend on the browser version but I think it will become more generalized in the future.

If I knew how to combine creating audio files and playback using the Powerpac player I would do that but I think it's probably beyond my capabilities. I have just adapted a Github project which first creates a wav file and then converts it to mp3. The two files are ready almost simultaneously. Originally there was no visible audio object. I have added this recently as I intend to use it to play half a second of silence the first time the user clicks a button to try to overcome the auto play restriction.

John
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 3 guests

cron