Home > other >  Xcode system("afplay music.wav"); doesn't seem to work
Xcode system("afplay music.wav"); doesn't seem to work

Time:10-30

I am writing a Command-Line C Application when after browsing through stack overflow I found this: Playing .wav C Mac, the answers state that using system("afplay music.wav"); plays music, but this doesn't seem to be working for me, I stored the music exactly where my main.c is located. I am not using any external libraries and I am not a pro at c so it would be appreciated if you would simplify things :)

Here is the code

void main()
{
    system("afplay IntroSpeechByGuide.wav");
}

CodePudding user response:

I stored the music exactly where my main.c

Most likely, afplay cannot find the audio file. The current directory of your application is certainly not the directory where your main.c is.

Either provide the full path to the audio file:

void main()
{
    system("afplay /Users/me/Documents/AudioFiles/IntroSpeechByGuide.wav");
}

Or change the working directory to the directory where the audio file is. It can be changed by going to Product / Scheme / Edit Scheme.

  • Related