Thread: How to play an audio file in c program?

  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,793
    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,868
    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, 09:35 AM
  2. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05: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, 12:39 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM