• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1653
  • Last Modified:

mciSendString examples wanted

Does anyone one know answers to these specific questions
using mciSendString?

For example to play an Audio CD I use
MCIERROR err = mciSendString("play cdaudio",NULL,0,NULL);
and to stop
MCIERROR err = mciSendString("stop cdaudio",NULL,0,NULL);
which works fine.

But I would like to know how to do the following:

1. Determine the number of Tracks on a CD. (use status)
2. Play the CD from a certain track number.(from pos to pos)
3. Play a midi file.

Thanks,  Btw the third question is there in case you know
it but not essential to get the points
0
vinny5
Asked:
vinny5
1 Solution
 
vinny5Author Commented:
Edited text of question
0
 
vinny5Author Commented:
Adjusted points to 400
0
 
rajesh032097Commented:
"myaudio" is the alias name used in opening the device.
1. No of tracks on cd :
mciSendString("status myaudio number of tracks")
2. Play CD from certain track position
First set the time format to tracks using
mciSendString("set myaudio time format tmsf")
and then calling
mciSendString("play myaudio from %d", nTrackNo) where nTrackNo is the track number from which you want to start the playback. You can also specify the position upto which you want to play the CD and whether playback should be asynchronous or synchronous in the same command.
3. Stop CD player:
mciSendString("stop myaudio")

and finally call "close myaudio" when you are done with the device.
I haven't tried it for midi but it should be same. You can find all command specifications in the VC++ help.
Hope this helps.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
vinny5Author Commented:
Thanks for the answer rajesh but I still need somethings cleared up.

>"myaudio" is the alias name used in opening the device.
why isnt that cdaudio?

1. No of tracks on cd :
mciSendString("status myaudio number of tracks")

where does the number get stored to and If I try to compile this line VC++ 5.0 tells me

error C2660: 'mciSendStringA' : function does not take 1 parameters

I dont know why the 'A' is there in  mciSendStringA but they are right. mciSendString needs

MCIERROR mciSendString( LPCTSTR lpszCommand,          LPTSTR lpszReturnString,
         UINT cchReturn,
         HANDLE hwndCallback );

so similarly the other mciSendString examples you said wont work.
Is there something that Im doing wrong?


0
 
vinny5Author Commented:
Thanks for the answer rajesh but I could not get what you said to work.  I had some questions on your response:

>"myaudio" is the alias name used in opening the device.
why isnt that cdaudio?

1. No of tracks on cd :
mciSendString("status myaudio number of tracks")

where does the track number get stored to?
and If I try to compile this line VC++ 5.0 tells me

error C2660: 'mciSendStringA' : function does not take 1 parameters

I dont know why the 'A' is there in  mciSendStringA but they are right. mciSendString needs

MCIERROR mciSendString( LPCTSTR lpszCommand,          
         LPTSTR lpszReturnString,
         UINT cchReturn,
         HANDLE hwndCallback );

so similarly the other mciSendString examples you said wont work.
Is there something that Im doing wrong?


0
 
jtwine100697Commented:
  "myaudio" is an alias that you specify when opening the desired MCI device.  From then on, you reference it by that alias.

   Look up (in the help system) the "status" MCI command.  It will tell you what parameters are required, and how to obtain results from the command(s).

   I have a simple class for playing MIDI (.MID/.RMI) files, if you are interested...

-=- James.
0
 
chensuCommented:
Do you want the examples using mciSendCommand instead of mciSendString?
0
 
rajesh032097Commented:
Hi,
Alias is the name you specify for the device when you open it. It's needed since subsequent functions expect it as a parameter. Also it helps in distinguishing the devices easily especially if you have multiple devices on your machine ( say 2 CD players).
I thought you would refer to the correct syntax of the mciSendString() function by referrring to VC++ help. Anyway, mciSendString function has following syntax :
MCIERROR mciSendString( LPCTSTR lpszCommand, LPTSTR lpszReturnString,
UINT cchReturn, HANDLE hwndCallback );
 
lpszCommand -> string that identifies the command
lpszReturnString->place holder for return information
cchReturn->Size of lpszReturnString
hwndCallback->Window handle which can receive notification of mci commands if you specify "notify" flag in the command ( applicable only to a subset of the mci commands)

So, for e.g., your fisrt command can be written in following way :
void OpenCD()
{
char Buf[1000];
int nRet;
nRet = ::mciSendString("open cdaudio alias myplay shareable ",
      Buf, 1000, NULL);
if(nRet)
{
      ::mciGetErrorString(nRet, Buf,1000);
      ::MessageBox(NULL, Buf, NULL, MB_OK);
}

}

In case of command "status myaudio number of tracks" , or any command which is supposed to return some information, it would store it in lpszReturnString parameter after the function returns successfully.

All the mciSendString functions would be almost identical to the above unless you have a "notify" flag. If you want your application to continue without waiting for the playback, then you can specify "notify" flag in the lpszCommand string and then the handle of the window that you pass as fourth parameter is used by MCI for sending notifications. For example, if you want to receive notification after playback, your command may look like this:

void PlayCD(int nFrom, int nTo)
{
      char Buf[1000];
      int nRet;
      CString strMsg;
      strMsg.Format("play myplay from %d to %d notify",nFrom, nTo);
      nRet = ::mciSendString(strMsg.GetBuffer(1024),
            Buf, 1000, hWnd);
      if(nRet)
      {
            ::mciGetErrorString(nRet, Buf,1000);
            ::MessageBox(NULL, Buf, NULL, MB_OK);
      }
}

Again, I repeat, all  commands are well documented ( fortunately :-) ) in VC++ help section. And their usage is very simple and identical.
Also you need not worry about compiler output names since they are internal to the implementation. We need not bother about mciSendStringA. For the user, it's just mciSendString.
Hope this helps you now.



0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now