Skip to content

How can i play sound with samples i created and put in a (byte)table ?

chris vans

Asked Feb 6, 2006, 12:11 AM EST1 answer
Share
LinkedInX
Hello,
I would like to play a sound. In fact i created the samples by my own, and put them in a table. Now i would like to play it. But i only found some things allowing to play wav files for exemple.
I specify that i DON'T want to store it in a wav file before, it has to be quick and i dont want to create a file on my hard disk, i only want to play my sound.
If any of you have a solution, i would be grateful.

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Java
    Try this approach:
    //GetMySoundData could be the place where you
    
    //create your sound data
    
    byte[] soundBuffer = 
    GetMySoundData();
    
    //create memory stream that is used to 
    read the buffer
    
    System.IO.MemoryStream 
    soundStream = new 
    System.IO.MemoryStream(soundBuffer);
    
    
    //now intialize the player
    
    System.Media.SoundPlayer 
    player = new 
    System.Media.SoundPlayer(soundStream);
    
    try
    
    {
    
        //play sound directly 
    from memory stream
    
        player.Play();
    
    }
    
    catch (InvalidOperationException 
    ex)
    
    {
    
        MessageBox.Show(ex.Message);
    
    }

    Hope that helps. I haven't got time to test this. It compiles on C# 2.0. You just have to make sure that the data in the buffer is formatted correclty. If you get that working, please let me know:)

    0