Jump to content
  • Advertisement
Sign in to follow this  
bikola_p

Media Player

This topic is 4822 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey Guys im working on a media player, but i cant get certain files to play, the thing is im using mcisendstring and im passing the filename. Anyway, i can play certain wav file(wav files that have no space in the name)But cant play mp3 files, what's up with that. So:- test.wav works tes t.wav doesnt work anything with .mp3 doesnt work here is the code, please help. note: sFileName is the string containing the full file path. case ID_PLAY: { string FileName; //OPENING FILE FileName="open \""+sFileName+"\" type mpegvideoaudio alias mfile"; mciSendString(FileName.c_str(),NULL, 0,0); MessageBox(hwnd,FileName.c_str(),"Test",0); //PLAYING FILE FileName="play \""+sFileName+"\" from 0"; mciSendString(FileName.c_str(),NULL,0,0); MessageBox(hwnd,FileName.c_str(),"Test",0); goto start; } break; I have the Message Box after each mcisendstring to see what the FileName passed is, this i also done to see the file path to see if the spaces are ignored etc. Turns out after both opening and playing the file path displayed in the message box is correct and includes the spaces,if i had tes t.wav in my C: the message box would first after open display open "c:\tes t.wav" type mpegaudio alias myfile and after play, the message box displays play "c:\tes t.wav" from 0 This output is correct and is what is being fed to the mcisendstring function. HOWEVER it Doesnt PLAY.Same thing with mp3's I renamed tes t.wav to test.wav and the output was open "c:\test.wav" type mpegaudio alias myfile and after play, the message box displays play "c:\test.wav" from 0 This again is correct output, and guess what, it PLAYS. Whats up with this?

Share this post


Link to post
Share on other sites
Advertisement
I'm think you'll need to decompress the mp3 yourself (although your question is quite hard to understand). There's plenty of free-software mp3 decoders that you can learn from.

Share this post


Link to post
Share on other sites
ok, apart from the mp3 part, how come i can play files that contain no spaces, but cannot play files with spaces in the names? I checked my code over and over, and even display the filename stored in the variables to see if the space truncates the following letters etc, however the filename with or without the sapce both come out correctly.

Share this post


Link to post
Share on other sites
I haven't really used MCI before, but my guess would be that you should use
play myfile from 0

instead of
play "C:\test.wav" from 0

given that you are assigning the opened file the alias myfile.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by bikola_p
... how come i can play files that contain no spaces, but cannot play files with spaces in the names.


Think about it. Lets say that you have the command string

"open my audio file.wav alias mfile"

How MCI works is that it parses that string and determines what you intened to do. So it sees open and realizes that you want to open some file. Ok what is the next parameter -- "my". Ok I can do that I think. Lets see "my". I cannot find the file "my" anyware in the local directory. Abort.

if you use the shortfile format (8.3) from the old DOS days it will contain no spaces and it will work as intended.

As far as the not playing mp3's I am not really sure. I would try to remove the "type mpegvideoaudio".


Check out this program. It is a 32-bit console based Media Player that uses teh mciSendString. I could not get it to run without crashing the program when I loaded all the mp3s into the program and it stated to play the first file. The code is hard to follow but the important mci commands are easily spotted.

I hate to directly link to the file but their site has some problems right now.
http://www.cpp-home.com/downloads/code/298.zip


I have used the above DOS Media Player source code to extract various mci command strings and I am in the process of writing my own mp3 player. Here is the play method of my class. alias is just "song01" for now. I am planning on being able to allow multiple mp3s being played at the same time.


bool
Sound::Play(std::string filename){
char buffer[128];
snprintf(buffer, 128, "open %s alias %s", filename.c_str(), alias.c_str());
int err = mciSendString(buffer,0,0,0);
if (err > 0){
return false;
}

// speed of 1000 is normal, 2000 is 2x as fast, 500 is half as fast
// as normal I did manage to get speed to 2200 without too much
// trouble. A speed of 2400 did not play the mp3 file.

snprintf(buffer, 128, "set %s speed %d", alias.c_str(), speed);
err = mciSendString(buffer,0,0,0);
if (err > 0){
return false;
}

snprintf(buffer, 128, "play %s", alias.c_str());
err = mciSendString(buffer,0,0,0);
if (err > 0){
return false;
}
return true;
}


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!