How to play an audio file in c program?

This is a discussion on How to play an audio file in c program? within the Windows Programming forums, part of the Platform Specific Boards category; Please can any one tell me how to open an audio file in C Program? I came across a function ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    3

    Smile How to play an audio file in c program?

    Please can any one tell me how to open an audio file in C Program?
    I came across a function "fopen", but i think its for opening text file. If i m wrong with that, can anyone tell me how to open audio file using "fopen".

  2. #2
    Registered User
    Join Date
    Jan 2009
    Location
    Australia
    Posts
    375
    There are three ways that I know of to play an audio file:

    MCI
    waveOut
    DirectSound

    I haven't really used them that much, so I can't help you at all with how to use them. Google their names to find out about them.

  3. #3
    Registered User
    Join Date
    Nov 2009
    Posts
    3
    Thanks i will try it.

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,786
    If you just want it to open in the app that the user has installed for that file type (Winamp, Windows Media Player, etc) try ShellExecute

    Cprogramming.com FAQ > Run a program from within a program

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,854
    simplest way is with PlaySound() from Winmm.lib


    Code:
    char szFullPath[MAX_PATH]="c://sounds//somesound.wav";
    
    PlaySound(szFullPath, NULL, SND_FILENAME);
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 08:35 AM
  2. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 04:02 AM
  3. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 11:39 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21