Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6185001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:38:13+00:00 2026-05-24T01:38:13+00:00

So, I am building a web app that has a div with text that

  • 0

So, I am building a web app that has a div with text that changes on various user actions (it’s stepping through an array of pieces of text). I’m trying to add audio to it, so I made another array with the sound files in the appropriate positions:

var phrases=['Please hand me the awl.','etc1','etc2','etc3'];
var phrasesAudio=['awl.mp3','etc1.mp3','etc2.mp3','etc3.mp3'];

And on each action completion, a ‘counter’ variable in incremented, and each array looks for the object at that counter

var audio  = document.createElement("audio"),
canPlayMP3 = (typeof audio.canPlayType === "function" &&
              audio.canPlayType("audio/mpeg") !== "");
function onAction(){
correct++;
document.getElementById('speech').innerHTML=phrases[correct];
if(canPlayMP3){
    snd = new Audio(phrasesAudio[correct]);
}
else{
    snd = new Audio(phrasesAudioOgg[correct]);
}
snd.play();
}

(the text replaces a div’s HTML and I use .play() for the audio object)…usually works okay (and ALWAYS does in a ‘real’ browser), but on the iPad (the actual target device) after a few successful iterations, the TEXT continues to progress accurately, but the AUDIO will hiccup and repeat a sound file one or more times. I added some logging and looking there it reports that it’s playing screw.mp3 (just an example, no particular file is more or less error prone), but in actuality it plays screwdriver.mp3 (the prior file, if there is an error, the audio always LAGS, never LEADS)…because of this I am thinking that the problem is with my use of .play()…so I tried setting snd=null; between each sound, but nothing changed…Any suggestions for how to proceed? This is my first use of audio elements so any advice is appreciated. Thanks.

edit: I’ve also tried setting the files with snd.src (based on https://wiki.mozilla.org/Audio_Data_API) and this caused no audio to play

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T01:38:15+00:00Added an answer on May 24, 2026 at 1:38 am

    for iPad you need to call snd.load() before snd.play() – otherwise you get “odd” behaviour…

    see for some insight:
    http://jnjnjn.com/187/playing-audio-on-the-ipad-with-html5-and-javascript/
    Autoplay audio files on an iPad with HTML5

    EDIT – as per comment from the OP:

    Here https://developer.mozilla.org/En/Using_audio_and_video_in_Firefox you can find a tip on halting a currently playing piece of media with

    var mediaElement = document.getElementById("myMediaElementID"); 
    mediaElement.pause(); 
    mediaElement.src = ""; 
    

    and, following that with setting the correct src, load(), play() works great

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently building a web-app that has one section where the user sees a
I have a web app that has standard user model information. I am building
I'm building a new web app that has a requirement to generate an internal
I'm building a web app that has a grid of many small scrollable divs
I have a web app I'm building that has about 50 forms. I have
I've got a web app I'm building in ASP.NET that has the following security
I'm building a web-based productivity application that has to deal with modest user concurrency,
We're building a large web app that has numerous layers. In order to communicate
I am building a Django powered web app that has a large database component.
I'm building a web-app that handles internal emails and other frequent small-to-medium sized chunks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.