Thread: Playing sound files...

  1. #16
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    What's with "ElastoManiac"?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  2. #17
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  3. #18
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    I get "The page cannot be displayed". I'll try it later.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #19
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377
    allright...
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  5. #20
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133
    Good to know that this is a very friendly forum. Anyway; to dwks this doesn't work:
    PHP Code:
    mciSendString "Play \"blah blah.mp3\""00); 
    That's why I gonna rename the file.

  6. #21
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377
    if you ask me, the best thing to use for playing music/sound is FMod.
    It's absolutly simple to use.
    And it supports just about every platform.
    It's the most powerfull api for audio, so check it out http://www.fmod.org/
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  7. #22
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    I dug out some mci sample code. It definitely handles long file names.
    Code:
    #include <windows.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <tchar.h>
    
    #if defined(_MSC_VER)
    #  pragma comment(lib, "Winmm.lib")
    #endif
    
    
    /*
     * Returns the length, in milliseconds, of an MP3 or WMA file.
     */
    ULONG GetSongLength(LPCTSTR szFile)
    {
    	TCHAR szCommandString[1000];
    	TCHAR szResult[100];
    
    	wsprintf(szCommandString, TEXT("open \"%s\" type mpegvideo alias TempFile"), szFile);
    
    	if (ERROR_SUCCESS == mciSendString(szCommandString, NULL, 0, NULL) &&
    	    ERROR_SUCCESS == mciSendString(TEXT("set TempFile time format milliseconds"), NULL, 0, NULL) &&
    	    ERROR_SUCCESS == mciSendString(TEXT("status TempFile length"), szResult, 100, NULL) &&
    	    ERROR_SUCCESS == mciSendString(TEXT("close TempFile"), NULL, 0, NULL))
    	{
    		return _tcstoul(szResult, NULL, 10);
    	}
    
    	return 0;
    }
    
    
    /*
     * Plays an MP3 or WMA file.
     */
    BOOL PlaySong(LPCTSTR szFile)
    {
    	TCHAR szCommandString[1000];
    
    	wsprintf(szCommandString, TEXT("open \"%s\" type mpegvideo alias MediaFile"), szFile);
    
    	/* By default mci functions will return immediately and the task will be carried out
    	 * asynchronously. To have the function wait, place the word "wait" at the end of the
    	 * command string. ie. "play MediaFile wait" */	 
    	if (ERROR_SUCCESS == mciSendString(szCommandString, NULL, 0, NULL) &&
    	    ERROR_SUCCESS == mciSendString(TEXT("play MediaFile"), NULL, 0, NULL))
    	{
    		return TRUE;
    	}
    
    	return FALSE;
    }
    
    int main(void)
    {
    	ULONG length, mins, secs, tsecs;
    
    	/* Get the length of the song in milliseconds. */
    	length = GetSongLength(TEXT("C:\\Path To\\Your song.mp3"));
    
    	/* Convert to minutes, seconds, tenths of a second. */
    	mins  = length / 60000;
    	secs  = (length % 60000) / 1000;
    	tsecs = (length % 1000)  / 100;
    
    	/* Print out length of song. */
    	printf("The length of the song is %lu milliseconds (%lu:%02lu.%lu).\n",
    	        length, mins, secs, tsecs);
    
    	/* Play song. */
    	if (!PlaySong(TEXT("C:\\Path To\\Your song.mp3")))
    	{
    		printf("Failed to play song!");
    	}
    
    	getchar();
    	return 0;
    }
    Last edited by anonytmouse; 12-11-2005 at 12:00 PM.

  8. #23
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133
    Omg, really really thanks dude, you have saved my project! I already wasn't really looking forward on Fmod thing, I noticed that Fmod also doesn't run on Dev-C++. Don't got much time now but I will look into it soon.
    Thanks Yuri.

  9. #24
    Registered User
    Join Date
    May 2006
    Posts
    1
    when I tried this, it gave a could not find file error
    all I did was change both the directories to C:\\windows\\desktop\\sound.mp3
    and yes, I have that file on my desktop

    --oops I just did a search and didn't look at the dates
    Last edited by HForN; 05-27-2006 at 09:27 AM.

  10. #25
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Could you please not bump old threads. If you want to discuss an issue raised in an ancient thread, simply create a new one with a reference link to the original.

    Quote Originally Posted by kermi3
    Welcome to the boards. If you haven't already done so then please take some time to familiarise yourself with the faq:
    http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

    Make sure you have a look at the the posting guidelines:
    http://cboard.cprogramming.com/annou...ouncementid=51
    Following the rules will ensure you get a prompt answer to your question.

    Remember, too, that the board has a search facility, a link is at the top of your screen:
    http://cboard.cprogramming.com/search.php
    It will often get you a quicker answer to your questions than waiting for a response to one you have posted.


    If you have any questions about this you may ask or you can contact one of our forum leaders:

    http://cboard.cprogramming.com/showgroups.php
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Playing MP3 files in C++
    By peyman_k in forum C++ Programming
    Replies: 6
    Last Post: 07-29-2008, 05:25 PM
  2. Playing a sound wave?
    By Blackroot in forum C++ Programming
    Replies: 1
    Last Post: 01-08-2006, 02:01 AM
  3. Playing sound without internal speaker in C
    By Rainy in forum C Programming
    Replies: 1
    Last Post: 03-30-2005, 11:24 AM
  4. I Need To Know Some Things That I Can Put Into A Batch File
    By TheRealNapster in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 10-20-2003, 08:12 PM
  5. Help me modify my Sound Server
    By zdude in forum C Programming
    Replies: 1
    Last Post: 05-14-2003, 05:15 PM