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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:29:43+00:00 2026-05-23T12:29:43+00:00

My question is the following: How do I set up an array of sounds,

  • 0

My question is the following:

How do I set up an array of sounds, so that a single button can play them? I have 5 wavs (sounds1.wav, sounds2.wav …. sounds5.wav), and ideally I would like for them to be random instead of a set order, but i have absolutely no idea if that is possible.

I am using this code as a basis:

var stream = TitleContainer.OpenStream("Sounds/sound1.wav");
     var effect = SoundEffect.FromStream(stream);
     FrameworkDispatcher.Update();
     effect.Play();

Any help is appreciated. 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-05-23T12:29:44+00:00Added an answer on May 23, 2026 at 12:29 pm

    You could store them in an array of streams, but it’s only a good idea to do this if your wav files aren’t big as you may surpass the 90mb memory usage limit if they are.

    Stream[] myStreamArray = new Stream[5];
    myStreamArray[0] = TitleContainer.OpenStream("Sounds/sound1.wav");
    //etc.. (you could use a for loop if your sounds are named in a pattern)
    

    You can then pick a random number, using the Random class, from 0 to 4 (inclusive). This will mean that the chosen sound will be random instead of playing in any particular order.
    To play, you can just use your code above but replace the FromStream line to something like this:

    var effect = SoundEffect.FromStream(myStreamArray[randomNumber]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My question is motivated by the following problem. I have a set of web
I have the following question about JPA: Can I save the order of the
Quick Question: I have the following array (multidimensional): Array ( [preorder] => 0 [data]
Possible Duplicate: tcl array question - key with quotes I have the following code:
I have a question that has me stumped, maybe you can help. I have
For the following question, I am looking for an answer that is based on
I have code that manipulates binary files using fstream with the binary flag set
I am using jQuery 1.7.1. and I have the following question/problem: The code has
I've a question regarding the following code: #include all_needed.h static uint8_t array[2] = {0};
Can anyone tell me why the following code might not cycle through the array

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.