Results 1 to 11 of 11

Thread: [RESOLVED] how to add a .wav file into your project

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2006
    Posts
    41

    [RESOLVED] how to add a .wav file into your project

    Hey everyone. I am back Well anywho, I was wondering how would I go about adding a .wav file to my project? I would be doing a console application and want the .wav to be played once the program is executed. How would I go about doing this? Thanks ahead of time!
    Last edited by Visionary; Nov 9th, 2006 at 10:37 AM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: how to add a .wav file into your project

    Use a SoundPlayer object. I'm assuming that you're using C# 2.0. Maybe you could specify in future.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    Re: how to add a .wav file into your project


  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: how to add a .wav file into your project

    No need to resort to API functions, assuming that this is for .NET 2.0. I didn't mention how to get the wave file into your project in the first place though. Go to the Resources tab of the project properties and add a new audio resource. I created a console app and added the notify.wav file from my C:\Windows\Media folder to the project resources. I then ran this code:
    Code:
    class Program
    {
        static void Main(string[] args)
        {
            using (System.Media.SoundPlayer sp = new System.Media.SoundPlayer(Properties.Resources.notify))
            {
                sp.PlayLooping();
                Console.ReadLine();
            }
        }
    }
    The app ran and played the sound until I hit Enter.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    Re: how to add a .wav file into your project

    Nice one JM. I never thought that the 2.0 have that kind of capabilities.

    I will try that one to create a wannabe winamp application.

  6. #6

    Thread Starter
    Member
    Join Date
    Jul 2006
    Posts
    41

    Re: how to add a .wav file into your project

    Thanks! The code works for me! I was wondering is it possible to set the volume to be higher and if the volume is muted, unmute it in code?

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: how to add a .wav file into your project

    Quote Originally Posted by Visionary
    Thanks! The code works for me! I was wondering is it possible to set the volume to be higher and if the volume is muted, unmute it in code?
    I think that that would require you to use the Windows API. I couldn't tell you which functions but I know I've seen that information on the Web before. If you can't find the information on this site then a Web search should turn up what you need.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: how to add a .wav file into your project

    Quote Originally Posted by mar_zim
    Nice one JM. I never thought that the 2.0 have that kind of capabilities.

    I will try that one to create a wannabe winamp application.
    Note that the SoundPlayer is for wave files only. If you want to create low-level code for a media player then Windows MCI would be the way to go.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    Re: how to add a .wav file into your project

    Oh so it's only for wav files. Too bad I wish it could play an mp3 file. ok I'll look it up about Windows MCI.

    btw thanks.

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: how to add a .wav file into your project

    Quote Originally Posted by mar_zim
    Oh so it's only for wav files. Too bad I wish it could play an mp3 file. ok I'll look it up about Windows MCI.

    btw thanks.
    Getting a bit off the original topic but you may like to follow the Mentalis link in my signature and check out their Multimedia class. I'm fairly certain that it uses MCI to handle multiple sound file formats.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  11. #11

    Thread Starter
    Member
    Join Date
    Jul 2006
    Posts
    41

    Re: how to add a .wav file into your project

    Quote Originally Posted by mar_zim
    Oh so it's only for wav files. Too bad I wish it could play an mp3 file. ok I'll look it up about Windows MCI.

    btw thanks.
    you could always convert .mp3 to .wav but it might lower the quality.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width