-----------------------------------------------------------

New Message on cochindotnet

-----------------------------------------------------------
From: spark
Message 1 in Discussion


Hi,
this is your weekend 
take home :)
 
    I 
had some free time in office today so i thought i'd write some code, wrote 
myself a media player to rival microsoft's media player :)) (or something like 
that... ).
The player is 
actually a console to the media control interface within your windows system and 
you send the media interface commands in text - just like a command prompt ... 
this is one more of those many lesser know things in your alice-in-wonder... 
(oops ) operating system.
    I 
thought i'd give you code to show how this happens: the src is 2 files, one cpp 
and one cs (c#). both files have their compilation commands 
given.
 
//filename: 
mci.cpp
//compile: cl /LD mci.cpp /link winmm.lib kernel32.lib
#include 
<windows.h>
#include <stdio.h>
#define PATH 
1024
 
extern "C" 
__declspec(dllexport)
int mci(char * str,char * resp) 
{ 
 int 
ret;
 
 //convert one "" region to ShortPath to help 

 //out poor MCI's long path parsing capabilities
 char * p = 
str, *s;
 char short_path[PATH];
 s=0;
 while(*p 
&& *p !='\"') p++;
 if(*p)
 {
  s = 
p+1;
  while(*s && *s!='\"') s++;
 }
 if(*p 
&& s && *s)
 {
  *p = *s = 
0;
  GetShortPathName(p+1,short_path,PATH);
  //i 
assume somethings about path sizes for this sprintf 
...
  sprintf(str,"%s %s 
%s",str,short_path,s+1);
  printf("#>%s\n",str);
 }
 
 //the 
now good stuff
 if( ret = 
mciSendString(str,0,0,0))
  mciGetErrorString(ret,resp,2048);
 return 
ret;
}

and the c# 

 
//filename: 
mci.cs
//compile: csc mci.cs
using System;
using System.Text;
using 
System.Runtime.InteropServices;
 
class 
Mci
{
 [DllImport("mci.dll")]
 static extern int mci(string 
cmd,StringBuilder sb);
 
 static void 
Main()
 {
  Console.WriteLine("MCI Console/Player - Roshan 
James (1 Aug 2003)\ntype \"exit\" to quit");
  StringBuilder sb = 
new StringBuilder(2050);
  string cmd;
  int 
ret;
  
  while(true)
  {
   Console.Write("mci>");
   cmd 
= Console.ReadLine();
   
   if(cmd == 
"exit") break;
   else if((ret=mci(cmd,sb)) != 
0)
    Console.WriteLine("{0}: 
{1}",ret,sb.ToString());
  }
 }
}
 
So this code creates 
a mci.dll in cpp and interops with it in c# and interface with win32api , this 
case mci (mostly). In some senses this is proof of concept of somethings which 
some folk still stay doubtful.
You can use the src 
in this mail and compile it out yourself or if you are lazy download it from 
here :
http://www27.brinkster.com/sparksite/downloads/mci_src_and_bin.zip
 
So how do you use 
this ?
To play use this 
command
    
play <filename>
To stop 

    
stop <filename>
simple ? there are 
lost more...

get a the full 
command list for the program here :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/mmcmdstr_4nub.asp
want to adjust sound quality ... take a look 
at the 'quality' command.
 
if its tedious to 
type the file name, simply drap and drop the file name into the command line. 

those on win2k and 
higher will notice that your F7 key will work :)
examples:
play 
"D:\music\assorted\Robbie Williams - Supreme.mp3"

stop "D:\music\assorted\Robbie Williams - 
Supreme.mp3"
 
try not to 
under-estimate it too much... after all it can play most music file types, play 
video .. and (ahem) maybe capture stuff from a video device like a 
vcr...
/*as a foot note, 
this has been there in windows for a long while... anyone who has used my old 
netshortcut (http://www27.brinkster.com/sparksite/netshortcut/netshortcut.htm) 
(written in vc++/mfc) might have noticed a the mci command: the same mci 
interface.*/
 
cheers
roshan
 
ps. bdotnet-ers: if 
there is time, maybe during my command line session the coming friday i 
will demo mci for you
pps. so much for 
ethical computing, apologies, i know i am showing off 
mp3s...
 

-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/cochindotnet/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you received 
this message by mistake, please click the "Remove" link below. On the pre-addressed 
e-mail message that opens, simply click "Send". Your e-mail address will be deleted 
from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to