Using system; Using system. runtime. interopservices; Using system. text; Using system. IO; Namespace clsmciplay { /// <Summary> /// Summary of clsmci. /// </Summary> Public class clsmci { Public clsmci () { // // Todo: add the constructor logic here // }// Define the string variable used by the API Function [Financialas (unmanagedtype. byvaltstr, sizeconst = 260)] Private string name = ""; [Financialas (unmanagedtype. byvaltstr, sizeconst = 128)] Private string durlength = ""; [Financialas (unmanagedtype. lptstr, sizeconst = 128)] Private string temstr = ""; Int ilong; // Defines the enumerated variables of the playback status. Public Enum state { Mplaying = 1, Mpuase = 2, Mstop = 3 }; // Structure Variable Public struct structmci { Public bool bmut; Public int idur; Public int IPOs; Public int ivol; Public int ibal; Public String INAME; Public state; }; Public structmci MC = new structmci (); // Obtain the playback file attributes Public String filename { Get { Return MC. INAME; } Set { // Asciiencoding ASC = new asciiencoding (); Try { Temstr = ""; Temstr = temstr. padleft (127, convert. tochar ("")); Name = Name. padleft (260, convert. tochar ("")); MC. INAME = value; Ilong = apiclass. getw.pathname (MC. INAME, name, name. Length ); Name = getcurrpath (name ); // Name = "open" + convert. tochar (34) + name + convert. tochar (34) + "alias Media "; Name = "open" + convert. tochar (34) + name + convert. tochar (34) + "alias Media "; Ilong = apiclass. mcisendstring ("close all", temstr, temstr. length, 0 ); Ilong = apiclass. mcisendstring (name, temstr, temstr. length, 0 ); Ilong = apiclass. mcisendstring ("set media time format milliseconds", temstr, temstr. length, 0 ); MC. State = state. mstop; } Catch { MessageBox. Show ("error! "); } } } // Play Public void play () { Temstr = ""; Temstr = temstr. padleft (127, convert. tochar ("")); Apiclass. mcisendstring ("play media", temstr, temstr. length, 0 ); MC. State = state. mplaying; } // Stop Public void stopt () { Temstr = ""; Temstr = temstr. padleft (128, convert. tochar ("")); Ilong = apiclass. mcisendstring ("close media", temstr, 128, 0 ); Ilong = apiclass. mcisendstring ("close all", temstr, 128, 0 ); MC. State = state. mstop; } Public void puase () { Temstr = ""; Temstr = temstr. padleft (128, convert. tochar ("")); Ilong = apiclass. mcisendstring ("Pause Media", temstr, temstr. length, 0 ); MC. State = state. mpuase; } Private string getcurrpath (string name) { If (name. Length <1) Return ""; Name = Name. Trim (); Name = Name. substring (0, name. Length-1 ); Return name; } // Total time Public int duration { Get { Durlength = ""; Durlength = durlength. padleft (128, convert. tochar ("")); Apiclass. mcisendstring ("status media length", durlength, durlength. length, 0 ); Durlength = durlength. Trim (); If (durlength = "") return 0; Return (INT) (convert. todouble (durlength)/1000f ); } } // Current time Public int currentposition { Get { Durlength = ""; Durlength = durlength. padleft (128, convert. tochar ("")); Apiclass. mcisendstring ("status Media Position", durlength, durlength. length, 0 ); MC. IPOs = (INT) (convert. todouble (durlength)/1000f ); Return MC. IPOs; } } } Public class apiclass { [Dllimport ("kernel32.dll", charset = charset. Auto)] Public static extern int getaskpathname ( String lpszlongpath, String delimiter file, Int cchbuffer ); [Dllimport ("winmm. dll", entrypoint = "mcisendstring", charset = charset. Auto)] Public static extern int mcisendstring ( String lpstrcommand, String lpstrreturnstring, Int ureturnlength, Int hwndcallback ); } } |