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 8554831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:58:24+00:00 2026-06-11T14:58:24+00:00

I had a javascript function and it works well: function playMp3(str) { … }

  • 0

I had a javascript function and it works well:

function playMp3(str) {
  ...
}

the other script:

function playMp3wholepage() {
  var dgs=new Array();
  dgs[0] = "/abc.mp3";
  dgs[1] = "/dac.mp3";
  dgs[2] = "/hf.mp3";
  ....
  dgs[28] = "/er23.mp3";
  dgs[29] = "/read/34_15.mp3";
  for (i=0;i<=29;i++){
    ses = dgs[i]
    setTimeout("playMp3(ses);", 2000)
  }
}

I want to play all of the sounds in the order that given in second script. but I could not get the second script run, it just play the last sound (dgs[29]), not all of them.

Thank you

  • 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-06-11T14:58:26+00:00Added an answer on June 11, 2026 at 2:58 pm

    When setTimeout callback execute, sec is already dgs[29], you need to create another function scope to perserve the value.

    for (var i=0; i<=dgs.length; i++){
       (function (i) {
           setTimeout(function() {
               playMp3(dgs[i]);
           }, 2000 * i);
       }(i));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example, if i had a variable in javascript var nombre; onclick=nombre='someValue' and somewhere
When writing a Javascript a function that I had gotten help from earlier ,
This is from Crockford's JavaScript: The Good Parts var is_array = function (value) {
I've created a Greasemonkey script which replaces a page function: (function() { var oldFunc
:I have the following in one of my partial views: <script type=text/javascript language=javascript> $(document).ready(function
I had a problem with some JavaScript functions that had me scratching my head
Question : Beginner Level Code: Pure Javascript I had created a web page in
Has anyone had any experience writing a web control (in either ASP.net, or javascript/HTML/CSS),
When working on some Javascript for a web application, I noticed that I had
How do I remove emoji code using JavaScript? I thought I had taken care

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.