Code
Using System;
Using System. text;
Using System. runtime. interopservices;
Namespace Music
{
/**/
/// <Summary>
///
/// </Summary>
Public Class Audio
{
[Dllimport ( " Winmm. dll " )]
Private Static Extern Int Mcisendstring
(
String Lpstrcommand,
String Lpstrreturnstring,
Int Ureturnlength,
Int Hwndcallback
);
[Dllimport ( " Kernel32.dll " , Charset = Charset. Auto)]
Public Static Extern Int Getmediapathname
(
[Financialas (unmanagedtype. lptstr)] String Path,
[Financialas (unmanagedtype. lptstr)] stringbuilder implements path,
Int Shortpathlength
);
PublicAudio ()
{
}
// Music. Audio. Play ("E: \ DIY \ 365crazyenglish \ resource \ 3.mp3 ");
Public Static Void Play ( String Filename)
{
Stringbuilder connector pathtemp = New Stringbuilder ( 255 );
Int Result = Getmediapathname (filename, callback pathtemp, callback pathtemp. capacity );
String Export path = Using pathtemp. tostring ();
Mcisendstring ( " Open " + Export path + " Alias song " , "" , 0 , 0 );
Mcisendstring ( " Play song " , "" , 0 , 0 );
}
Public void stop ()
{
mcisendstring ( " stop song " , "" , 0 , 0 );
}
Public void pause ()
{
mcisendstring ( " pause song " , "" , 0 , 0 );
}
Public VoidClose ()
{
Mcisendstring ("Close song","",0,0);
}
}
}
Axwindowsmediaplayer method loop playback
Code
Private Void Button#click ( Object Sender, eventargs E)
{
Axwindowsmediaplayer1.url = @" D: \ study \ My music \ perhapslove.pdf " ;
Axwindowsmediaplayer1.ctlcontrols. Play ();
Wmplib. iwmpplaylist currentlist = This . Axwindowsmediaplayer1.currentplaylist;
Wmplib. iwmpmedia media;
Media = This . Axwindowsmediaplayer1.newmedia ( @" D: \ study \ My music \ perhapslove.pdf " );
Currentlist. appenditem (media );
Media = This . Axwindowsmediaplayer1.newmedia ( @" D: \ study \ My music \ scratch your shoulders " );
Currentlist. appenditem (media );
}
Private VoidAxwindowsmediaplayer=playstatechange (ObjectSender, _ wmpocxevents_playstatechangeevent E)
{
Axwindowsmediaplayer1.ctlcontrols. Play ();
}