A summary of how C # plays background music

Source: Internet
Author: User

a summary of how C # plays background music

This article mainly introduced the C # Play background music method, the example summarizes the C # plays the background music the related skill, very has the practical value, needs the friend to be possible to refer to under

This article summarizes the method of C # playing background music. Share to everyone for your reference. The specific analysis is as follows:

The most written WinForm program, which is useful to play background music

Here are some online tutorials:

1. Calling unmanaged DLLs

?

1 2 3 4 5 6 7 8 9 10 11-12 Using System.Runtime.InteropServices; DllImport namespace Reference class Test//Beep {[DllImport ("Winmm.dll")] public static extern bool PlaySound (String filename,int Mod , int Flags); public void Main () {PlaySound (@ "D:/qm.wav", 0, 1);///replace 1 with 9 for continuous playback}}

2. Playback system with sound

?

1 2 3 4 5 System.Media.SystemSounds.Asterisk.Play (); System.Media.SystemSounds.Beep.Play (); System.Media.SystemSounds.Exclamation.Play (); System.Media.SystemSounds.Hand.Play (); System.Media.SystemSounds.Question.Play ();

3. Use System.Media.SoundPlayer to play WAV

?

1 2 3 System.Media.SoundPlayer sp = new SoundPlayer (); Sp. Soundlocation = @ "D:10sec.wav"; Sp. Playlooping ();

4. Use MCI Command string Multimedia Device program interface to play Mp3,avi, etc.

?

1 2 3 4 5 6 7 8 9 10 11-12 Using System.Runtime.InteropServices; public static UINT Snd_async = 0x0001; public static UINT snd_filename = 0x00020000; [DllImport ("Winmm.dll")] public static extern uint mciSendString (string lpstrcommand, String lpstrreturnstring, uint Ureturnlength, uint hwndcallback); public void Play () {mcisendstring (@ "Close Temp_alias", NULL, 0, 0); mciSendString (@ "open" "E:music blue and White porcelain. mp3" "Alias Temp_al IAS ", null,0,0); mciSendString ("Play Temp_alias repeat", NULL, 0, 0); }

For detailed parameter descriptions on mcisendstring, see MSDN, or Http://blog.csdn.net/psongchao/archive/2007/01/19/1487788.aspx

5, using the AxWindowsMediaPlayer COM components to play

A. Load COM components: Toolbox->choose items->com components->windows Media Player:

B. Drag and drop the Windows Media Player control into the WinForm form, and set the URL property in AxWindowsMediaPlayer1 to MP3 or Avi's file path, F5 run.

How do I use Windows Media Player to loop through the media files in my list?

Let's say we have a playlist and the following code can be used to loop automatically

?

1 2 3 4 5 6 7 8 9 10 11 12-13 private void Axwindowsmediaplayer1_playstatechange (object sender, Axwmplib._wmpocxevents_playstatechangeevent e) {if (axwindowsmediaplayer1.playstate = = WMPLib.WMPPlayState.wmppsMediaEnded) {Thread thread = new Thread (new ThreadStart (Playthread)); Start (); } private void Playthread () {Axwindowsmediaplayer1.url = @ "E:musicsomeone.avi"; AxWindowsMediaPlayer1.Ctlcontrols.play (); }

I hope this article will help you with the C # program.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.