using System.Media; using System.IO; SoundPlayer music = new SoundPlayer(); music = new SoundPlayer(""); music.Play(); 或 [DllImport("winmm.dll")] public static extern long PlaySound(String fileName,long a,long b); [DllImport("winmm.dll")] public static extern long mciSendString(string lpstrCommand,string lpstrReturnString,long length,long hwndcallback); public static void PlayMusic(string p_FileName) { try { mciSendString(@"close "+p_FileName ,"",0,0); mciSendString(@"open " + p_FileName,"",0,0); mciSendString(@"play " + p_FileName ,"",0,0); } catch { } }
我想应该开个线程用PlaySound不停的播放你的声音文件吧!
SoundPlayer Player = new SoundPlayer(); this.Player.SoundLocation = @"C:\123.wav"; this.Player.Play();
using System.Media; using System.IO; SoundPlayer music = new SoundPlayer(); music = new SoundPlayer(""); music.Play();
选择菜单中的“工具”中的“自定义工具箱(添加/移除工具箱项)”,在自定义工具箱的窗口中,点击展开“COM 组件”项,选中“Window Media Player”选项。确定后在“工具箱”中便会出现“Windows Media Player”这一项,然后再将其拖至Form上,将可见属性改为false,把AutoStart设置成为true(其实默认是true), 在form的load()中加入 axWindowsMediaPlayer1.URL = "C:\\123.mp3";
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;namespace music { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { System.Media.SoundPlayer sp = new System.Media.SoundPlayer(); sp.SoundLocation = System.IO.Directory.GetCurrentDirectory ()+ "\\1.wav"; sp.PlayLooping(); } } }
using System.IO;
SoundPlayer music = new SoundPlayer();
music = new SoundPlayer("");
music.Play();
或
[DllImport("winmm.dll")]
public static extern long PlaySound(String fileName,long a,long b); [DllImport("winmm.dll")]
public static extern long mciSendString(string lpstrCommand,string lpstrReturnString,long length,long hwndcallback);
public static void PlayMusic(string p_FileName)
{
try
{
mciSendString(@"close "+p_FileName ,"",0,0);
mciSendString(@"open " + p_FileName,"",0,0);
mciSendString(@"play " + p_FileName ,"",0,0);
}
catch
{
}
}
this.Player.SoundLocation = @"C:\123.wav";
this.Player.Play();
using System.IO;
SoundPlayer music = new SoundPlayer();
music = new SoundPlayer("");
music.Play();
在form的load()中加入
axWindowsMediaPlayer1.URL = "C:\\123.mp3";
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace music
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
System.Media.SoundPlayer sp = new System.Media.SoundPlayer();
sp.SoundLocation = System.IO.Directory.GetCurrentDirectory ()+ "\\1.wav";
sp.PlayLooping();
}
}
}
//相对路径
//sp.SoundLocation = @"alert1.wav"; //在bin\Debug 文件夹下。
//sp.SoundLocation = @"music\alert1.wav"; //在bin\Debug\music 文件夹下。
//sp.SoundLocation = Application.StartupPath + @"\alert1.wav";
//sp.SoundLocation = Application.StartupPath + @"\music\alert1.wav"; //绝对路径
sp.SoundLocation = @"F:\Visual Studio 2008\Projects\PersonalABC\bin\Debug\alert.wav"; sp.Play();