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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:23:48+00:00 2026-05-27T21:23:48+00:00

I have the following Play method for playing musical notes stored in an arraylist:

  • 0

I have the following Play method for playing musical notes stored in an arraylist:

public void Play(Duration d){


            int duration = 1;

            if (d == Duration.SemiBreve)
            {
                duration = 16;
            }

            else if (d == Duration.DotMin)
            {
                duration = 10;
            }

            else if (d == Duration.minim)
            {
                duration = 8;
            }

            else if (d == Duration.Crotchet)
            {
                duration = 4;
            }

            else if (d == Duration.Quaver)
            {
                duration = 2;
            }

            else if (d == Duration.SemiQuaver)
            {
                duration = 1;
            }

            player = new SoundPlayer();

            player.SoundLocation = "pathToLocation";


            //set timer
            time = new Timer();
            time.Tick += new EventHandler(clockTick);
            time.Interval = duration * 150;
            player.Play();
            time.Start();

        }

When I call the method with a button:

private void PlayButton_Click(object sender, EventArgs e)

{

        //Loops through the collection and plays each note one after the other
        foreach (MusicNote music in this.staff.Notes)
        {
            music.Play(music.Dur)

        }
    }

Only the last note gets played. With PlaySync() all the notes get played but the duration isn’t recognized. I also tried using threads like so:

foreach (MusicNote music in this.staff.Notes)
            {
                Thread t = new Thread(playMethod=>music.Play(music.Dur));  
                t.Start();
                t.Join();

            }

But it doesn’t work either. Any suggestions as to how I can get the files to play consecutively like with PlaySync but using their set duration?

  • 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-27T21:23:49+00:00Added an answer on May 27, 2026 at 9:23 pm

    You don’t wait for the timer anywhere. So in practice all notes get played almost simultaneously, causing just the last one to be effectively audible.


    UPDATE: Using the System.Timers.Timer class the way to go is registering a handler for the Elapsed event and playing the notes one-by-one in the event handler. This way you avoid freezing the UI.

    Another option is playing in a background thread and the using Thread.Sleep to wait. Here you will have to make sure the thread is stopped according to the state of the UI (i.e. the use closes the current dialog etc.).

    In either case to avoid race conditions you will have to solve concurrent access to staff.Notes or make a copy of it for the sake of playing it.

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

Sidebar

Related Questions

I have following classes. class A { public: void fun(); } class B: public
I have following code to play small audio files private void playVoice() { if
I have the following code: public void doJob() { MyObj s; for ( Object
I have the following code for Android which works fine to play a sound
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have the following Play Framework entity (using Morphia for persistence) as part of
I have a function with the following declaration: void playCard(string card); and the following
I have the following code var playingStream:NetStream; function playBytes(bytes:ByteArray): void { var connect_nc:NetConnection =
I have following situation: I have loged user, standard authentication with DB table $authAdapter
I have following string String str = replace :) :) with some other string;

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.