Hi guys. I have a question. Can you load .mp3 files using the fopen() function? I tried a very simple program out but, the file doesn't seem to load. Anyway, here is my code:
Should be able to open anything, if its not open in another program already. Check that the file is in the working directory (the dir w/ all your source if running from VS, with the exe otherwise)
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
If MarauderIIC's suggestion doesn't fix your problem and your running the code on an operating system that has case sensitive filenames, make sure that the case of the filename is correct.
Nothing works. I made sure the .exe file was in the same directory, the program outputs which song was played so, it doesn't return NULL. Read binary mode doesn't work either, as Amarant basically assumed. By the way, I use Dev-C++ as my IDE and I use Windows Vista, please don't bash me lol. Help a noob?
There are 10 types of people in this world; those who understand binary and those who don't.
---------------------------------------------------------------------------------------
I think I can program pretty well, it's my compiler that needs convincing!
--------------------------------------------------------------------------------------- And now a joke to lighten to mood :D
I wander what programming language anakin skywalker used to program C3-PO's AI back on tatooine? my guess is Jawa :P
programmerinprogress wrote:just out of curiosity, what are you trying to do?
(with the loaded .mp3?)
I want to load in an .mp3 file, so I can play a song. It's only an experiment, to see if I can get it to do something. I know it's pretty pointless but as I said, it's only an experiment.
There are 10 types of people in this world; those who understand binary and those who don't.
well, you know, the C/C++ IO systems treats files as streams, irrespective of their application or type, the idea is that you can get data in and out of your program, but if i'm understanding you correctly, you expect the program to randomly interpret the files as an audio file, and play it accordingly.
AFAIK, that's not how it works, to actually play an mp3 file, you need to use a library that can interpret (understand in other words) the file you're trying to access, and use the data from the streams to output the sounds, simply trying to load in the sound is not enough.
Now, if i've misread the situation, I don't mean to insult your knowledge of the subject, but if you want to play mp3, perhaps you could use one of the many audio libraries out there to accomplish this task (I can't remember if SDL_mixer supports mp3, but SDL_mixer has it's own audio loading functions, and allows you to stop, pause and play chunks of audio)
EDIT: when the term 'open' is used in C/C++, it refers to opening a file for reading or writing in/out streams of data, not actually 'opening' the file as you would an .exe file when you click it, again, if i've misread the situation, I totally apologise.
---------------------------------------------------------------------------------------
I think I can program pretty well, it's my compiler that needs convincing!
--------------------------------------------------------------------------------------- And now a joke to lighten to mood :D
I wander what programming language anakin skywalker used to program C3-PO's AI back on tatooine? my guess is Jawa :P
programmerinprogress wrote:well, you know, the C/C++ IO systems treats files as streams, irrespective of their application or type, the idea is that you can get data in and out of your program, but if i'm understanding you correctly, you expect the program to randomly interpret the files as an audio file, and play it accordingly.
AFAIK, that's not how it works, to actually play an mp3 file, you need to use a library that can interpret (understand in other words) the file you're trying to access, and use the data from the streams to output the sounds, simply trying to load in the sound is not enough.
Now, if i've misread the situation, I don't mean to insult your knowledge of the subject, but if you want to play mp3, perhaps you could use one of the many audio libraries out there to accomplish this task (I can't remember if SDL_mixer supports mp3, but SDL_mixer has it's own audio loading functions, and allows you to stop, pause and play chunks of audio)
EDIT: when the term 'open' is used in C/C++, it refers to opening a file for reading or writing in/out streams of data, not actually 'opening' the file as you would an .exe file when you click it, again, if i've misread the situation, I totally apologise.
Cheers man. I guess loading an .mp3 from a CLI based program isn't possible. I'll look more into SDL once I'm feeling more confident, using C. Btw, SDL_mixer does have support for .mp3 files.
There are 10 types of people in this world; those who understand binary and those who don't.
well, you know, it isn't actually the Command-line that opens the file, it's the application you invoke from the command-line that plays the file.
so yeah, if you found and application which takes an mp3 filepath as a command-line argument, you could open the file from the command-line, but to simply use C++ file streams to open the file and just expect it work work is impossible, you need a library that can interpret the data you're trying to stream in, and then toy need to write a program that uses that library.
---------------------------------------------------------------------------------------
I think I can program pretty well, it's my compiler that needs convincing!
--------------------------------------------------------------------------------------- And now a joke to lighten to mood :D
I wander what programming language anakin skywalker used to program C3-PO's AI back on tatooine? my guess is Jawa :P