2

I'm having some troubles with this "simple" program that im trying to build.

My goal is to create a C program which executes an mp3 sound file saying "Hello" and runs at Windows startup.

#include<stdio.h>

main(int argc, char *argv[]){

FILE *fp;
char s[100];
int i;


    if((fp=fopen("Hello.mp3","rb"))==NULL) //Open file and read on binary mode
       { 
         printf("Could not open the file\n");
         exit(1);
    }

fclose(fp);


 }

I think that to interpret the MP3 encoded data i must use an library but i realy need an help.

Best regards,

Ricardo

falkon21
  • 74
  • 2
  • 3
  • 15
  • Why don't you take a look at a similar question here: http://stackoverflow.com/questions/428884/how-to-play-mp3-files-in-c – Tuxdude Feb 28 '13 at 01:59

1 Answers1

3

I think we cannot open an mp3 file this way , like any regular text file.

fp=fopen("Hello.mp3","rb")

We have to use a codec , to actually play the mp3 file , or atleast use a library which has one.

Do take a look at these places.

How to play MP3 files in C?

SDL Sound Mix Tutorial

Community
  • 1
  • 1
Barath Ravikumar
  • 5,658
  • 3
  • 23
  • 39
  • Hum, what if we try to execute a command from the windows shell? Maybe using the ShellExecute(); command? I can't make it work.. I realy just wanna execute the C program and make it open the music.mp3 file.. – falkon21 Mar 02 '13 at 14:53
  • @RicardoCosta although i don't know why you want to do it :), yes you can open the mp3 file through a shell using a command line interface given by any audio player. On my Linux system i have mplayer installed so i have a program like this int main() { system("mplayer mp3file.mp3") } , now after that putting the mp3file.mp3 in the same directory of the program , and running it sure will open the mp3 file and play it – Barath Ravikumar Mar 02 '13 at 15:23
  • ok, but do you use any library for that? i mean, we cant just write: main(){ system("mplayer mp3file.mp3") } and what it run, isn't it? and i just wanna understand how to run any exe from the shell using a C program :P – falkon21 Mar 02 '13 at 15:35
  • #include #include int main( int argc, const char * argv[] ) { char command[] = "C:\\Users\\Ricardo\\Desktop\\Hello_ricardo.mp3"; int status = system( command ); system("pause"); } Now it's working, thanks! :) – falkon21 Mar 02 '13 at 15:47