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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:26:02+00:00 2026-06-13T17:26:02+00:00

I have a button. Every time it is clicked, a music is played. When

  • 0

I have a button. Every time it is clicked, a music is played. When it’s clicked the second time, the music resumes. I also want to visualize the music.

So i begin with html5 audio (complete code in http://jsfiddle.net/karenpeng/PAW7r/):

  $("#1").click(function(){
    audio1.src = '1.mp3';
    audio1.controls = true;
    audio1.autoplay = true;
    audio1.loop = true;

    source = context.createMediaElementSource(audio1);

    source.connect(analyser);
    analyser.connect(context.destination);
    });

But when it’s clicked more than once, it console.log error:

    Uncaught Error: INVALID_STATE_ERR: DOM Exception 11 

Then i change to use web audio API, and change the source to:

    source = context.createBufferSource();

The error is gone.

And then, i need to visualize it.
But ironicly, it only works in html5 audio!

(complete code in http://jsfiddle.net/karenpeng/FvgQF/, it does not work in jsfiddle cuz i dont know how to write processing.js script properly, but it does run on my pc)

     var audio = new Audio();
     audio.src = '2.mp3';
     audio.controls = true;
     audio.autoplay = true;
     audio.loop=true;
     var context = new webkitAudioContext();
     var analyser = context.createAnalyser();

     var source = context.createMediaElementSource(audio);
     source.connect(analyser);
     analyser.connect(context.destination);

     var freqData = new Uint8Array(analyser.frequencyBinCount);
     analyser.getByteFrequencyData(freqData);

         //visualization using freqData

when i change the source to :

    source = context.createBufferSource();

it does not show anything.

So is there way to visualize it and yet without error and enable it to resume again and again?

  • 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-13T17:26:03+00:00Added an answer on June 13, 2026 at 5:26 pm

    Actually, I believe the problem is that you’re trying to create a SECOND web audio node for the same media element. (Your code, when clicked, re-sets the SRC, controls, etc., but it’s not creating a new Audio().) You should either hang on to the MediaElementAudioSourceNode you created, or create new Audio elements.

    E.g.:

    var context = new webkitAudioContext();
    var analyser = context.createAnalyser();
    var source = null;    
    var audio0 = new Audio();
    
    $("#0").click(function(){
        audio0.src = 'http://www.bornemark.se/bb/mp3_demos/PoA_Sorlin_-_Stay_Up.mp3';
        audio0.controls = true;
        audio0.autoplay = true;
        audio0.loop = true;
    
        if (source==null) {
            source = context.createMediaElementSource(audio0);
            source.connect(analyser);
            analyser.connect(context.destination);
        }
    });​
    

    Hope that helps!

    -Chris Wilson

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

Sidebar

Related Questions

So essentially I want the UILabel to increment every time a button is clicked.
I have a link that changes text every time its clicked but I am
I'm trying to hide/show some divs depending on what button is clicked. Every time
I have a button inside every cell of my UITableView, but when the button
I have a lot of button inside my application and for every button i
Every row in my gridview is supposed to have a button/hyperlink that navigates to
I have an android listview filled with items. Every item has a button. This
friends, i have a EditText on simple activity with a button. when every i
I wanted to change the style of the button I'm using every time I
I have a jQuery function which monitors the 'beforeunload' status. So therefore every time

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.