Someone asked yesterday at http://winbile.net/bbshow to use mediaplayer.pdf music in wm5.
In fact, Microsoft has mentioned in a multimedia case. For details, refer:
Http://www.microsoft.com/china/MSDN/library/Mobility/pocketpc/WorkingwithMultimedia.mspx
The method is a little complicated, but fortunately you can download its sample and reference it in your Managed Project.
After all, there is no way to directly operate WMP in. NET Compact framework. However, even so, we can still use managedCodeControl Windows Media Player. The basic idea is to first create a separate process for media player, and then control media player by forgetting to send messages in the form of media player. Next let's take a look at how this is done through the managed code,
First, create a process and input the following parameters:
Wmpprocess = New Process ();
Wmpprocess. startinfo. filename = " Wmplayer.exe " ;
Wmpprocess. startinfo. Arguments = Wmpargs;
The arguments format should be as follows: "" \ My Documents \ testvideo. WMV ""/fullscreen "; the file path must be separated from the following parameters. in C # and VB, this method of adding double quotation marks is legal.
Then, start the process and start playing the music. (If you want the user's focus to remain on your form, you should place your form on the top ), more WMP support is provided in systems above wm5.0. You can access the name of the currently played track, artist name, album name, bit rate, the playback time (accurate to milliseconds) or even the music style. Below are some examples: Artist = Systemstate. mediaplayertrackartist;
Playingtrack = Systemstate. mediaplayertracktitle;
Album = Systemstate. mediaplayeralbumtitle;
Bitrate = Systemstate. mediaplayertrackbitrate;
Style = Systemstate. mediaplayertrackgenre;
Another question is how to stop mediaplayer? We can still indirectly control it by sending messages to the form, but here we need to use a local function sendmessage. The Code is as follows:
// Reference sendmessage and name it closewmp
Private Const Uint32 wm_close = 16 ;
[Dllimport ( " Coredll. dll " , Entrypoint = " Sendmessage " )]
Public Static Extern Int32 closewmp (intptr hwnd, uint32 MSG, int32 wparam, int32 lparam );
// This is the case when it is used.
Public Void Stopwmp ()
{
Myref. closewmp (wmpprocess. main1_whandle, wm_close,0,0);
}
ProgramThe running effect is as follows:
Click here to download the complete code.
All rights reserved by freesc Huang
Http://fox23.cnblogs.com
Hjd. Click [at] gmail.com
2008-2-18