本文整理汇总了C#中System.Media.SoundPlayer.Play方法的典型用法代码示例。如果您正苦于以下问题:C# SoundPlayer.Play方法的具体用法?C# SoundPlayer.Play怎么用?C# SoundPlayer.Play使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Media.SoundPlayer
的用法示例。
在下文中一共展示了SoundPlayer.Play方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AboutBox
public AboutBox()
{
InitializeComponent();
loc = label1.Location;
label1.Text = "";
try
{
var rm = new System.Resources.ResourceManager("BizHawk.Client.EmuHawk.Properties.Resources", GetType().Assembly);
sfx = new SoundPlayer(rm.GetStream("nothawk"));
sfx.Play();
}
catch
{
}
//panel1.Size = new System.Drawing.Size(1000, 1000);
//pictureBox5.GetType().GetMethod("SetStyle", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.InvokeMethod).Invoke(pictureBox5, new object[] { ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint, true });
pictureBox5.BackColor = Color.Transparent;
pictureBox5.SendToBack();
pictureBox3.BringToFront();
pictureBox2.BringToFront();
pictureBox1.BringToFront();
pictureBox5.Visible = false;
}
示例2: Form1_KeyDown
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Left)
{
pictureBox1.Left -= 10;
}
if (e.KeyData == Keys.Right)
{
pictureBox1.Left += 10;
}
if (e.KeyData == Keys.Up)
{
pictureBox1.Top -= 10;
}
if (e.KeyData == Keys.Down)
{
pictureBox1.Top += 10;
}
Rectangle dropRect = new Rectangle(200, 100, 350, 250);
isDragging = false;
if (dropRect.Contains(pictureBox1.Bounds))
{ SoundPlayer player = new SoundPlayer();
player.SoundLocation = @"C:\Users\admin\Music\tada.wav";
player.Play();
MessageBox.Show("Вы победили!", "Проверка попадания");
}
}
示例3: ProcessRequest
/// <summary>
/// Handle a request.
/// </summary>
/// <param name="pDisplay">The display which called this function.</param>
/// <param name="pSurface">The surface which this display is hosted on.</param>
/// <param name="dArguments">A dictionary of arguments which are passed to the function as parameters.</param>
/// <returns>True if the request was processed sucessfully. False if there was an error.</returns>
public bool ProcessRequest(Display pDisplay, Surface pSurface, JSObject dArguments)
{
// Check we have a sound file.
var sSound = dArguments.GetValueOrDefault("file", "");
if (sSound == null || sSound == "")
{
Log.Write("Cannot play sound. Are you missing a 'file' parameter.", pDisplay.ToString(), Log.Type.DisplayWarning);
return false;
}
// Attempt to play it.
try
{
SoundPlayer pSound = new SoundPlayer(sSound);
pSound.Play();
return true;
}
// Log warnings.
catch (Exception e)
{
Log.Write("Cannot play sound. " + e.Message, pDisplay.ToString(), Log.Type.DisplayWarning);
return false;
}
}
示例4: Play
public static void Play(SoundType type)
{
if (Environment.OSVersion.Platform == PlatformID.Unix) return;
if (type != SoundType.None) {
Stream sound;
switch (type) {
case SoundType.Click:
sound = Sounds.scificlick;
break;
case SoundType.Servo:
sound = Sounds.panel_move;
break;
case SoundType.BigClick:
sound = Sounds.button_click;
break;
default:
sound = null;
break;
}
if (sound != null) {
var sp = new SoundPlayer(sound);
sp.Play();
}
}
}
示例5: certo
public certo()
{
InitializeComponent();
SoundPlayer tocarSom = new SoundPlayer(@"C:\Users\Willian\Desktop\jogo\jogo\imagem\cuco.wav");
tocarSom.Play();
}
示例6: Lose
public static void Lose()
{
int rand = World.Rand (0, 1);
var file = new FileStream ("lose"+rand+".wav", FileMode.Open, FileAccess.Read, FileShare.Read);
player = new SoundPlayer(file);
player.Play();
}
示例7: BT_jogar_Click_1
private void BT_jogar_Click_1(object sender, EventArgs e)
{
Form7 objform7 = new Form7();
objform7.Show();
SoundPlayer IniciarPlayer = new SoundPlayer(@"G:\Arquivos de música.wav\DingDong.wav");
IniciarPlayer.Play();
}
示例8: Main
static void Main(string[] args)
{
string varURL = "";
SoundPlayer quote = new SoundPlayer();
Random randNum = new Random();
int selectedQuote = (randNum.Next(1, 3));
switch (selectedQuote)
{
case 1:
varURL = "http://www.wavsource.com/snds_2015-09-20_4380281261564803/tv/simpsons/apu/bastard.wav";
break;
case 2:
varURL = "http://www.wavsource.com/snds_2015-09-20_4380281261564803/tv/simpsons/apu/do_not_listen.wav";
break;
case 3:
varURL = "http://www.wavsource.com/snds_2015-09-20_4380281261564803/tv/simpsons/apu/hell.wav";
break;
default:
break;
}
quote.SoundLocation = varURL;
try
{
quote.Play();
}
catch (Exception e)
{
Console.WriteLine(@"i'm sorry, you are not connected to the internet. please reconnect and try again.");
}
Console.ReadLine();
}
示例9: OnDeath
private static void OnDeath(SoundPlayer sound = null)
{
if (sound != null)
{
try
{
sound.Play();
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
else
{
var rnd = new Random();
switch (rnd.Next(0, 5))
{
case 1:
OnDeath(rip);
break;
case 2:
OnDeath(tootanky);
break;
case 3:
OnDeath(noobteam);
break;
case 4:
OnDeath(death1);
break;
}
}
}
示例10: Play
private void Play(Object sender, EventArgs e)
{
SoundPlayer soundPlayer = new SoundPlayer(System.Environment.CurrentDirectory + @"\Resources\Audio\didi.wav");
//或者
//SoundPlayer soundPlayer = new SoundPlayer(@"Resources\Audio\didi.wav");
soundPlayer.Play();
}
示例11: DoEvent
public static void DoEvent(string eventName)
{
if (App.Settings.Current.Sounds.IsEnabled)
{
string path = App.Settings.Current.Sounds.GetPathByName(eventName);
if (!string.IsNullOrEmpty(path))
{
if (_player != null)
{
_player.Dispose();
}
try
{
_player = new SoundPlayer(path);
_player.Play();
}
catch (Exception ex)
{
_player = null;
System.Diagnostics.Debug.WriteLine(
string.Format("Unable to play audio file {0}: {1}", path, ex.Message));
}
}
}
}
示例12: PlayWavFile
/// <summary>
/// 播放指定路径的Wav文件
/// </summary>
/// <param name="FilePath">Wav路径</param>
/// <param name="PlayTime">持续播放时间(单位:秒)
/// <para />
/// -1:无限地循环播放; 0:只播放一次; 具体正整数:持续循环地播放指定时间
/// </param>
public static void PlayWavFile(string FilePath, int PlayTime)
{
//增强判断
if (File.Exists(FilePath) == false)
return;
//加载Wav文件
SoundPlayer Player = new SoundPlayer(FilePath);
//根据参数执行不同的行为
if (PlayTime < 0)
Player.PlayLooping();
else if (PlayTime == 0)
Player.Play();
else
{
lock (((ICollection)_playTimeList).SyncRoot)
{
Player.PlayLooping();
_playTimeList.Add(new PlayTime
{
Player = Player,
EndTime = DateTime.Now.AddSeconds(PlayTime)
});
}
}
}
示例13: Form1_Paint
private void Form1_Paint(object sender, PaintEventArgs e)
{
SoundPlayer player = new SoundPlayer();
player.SoundLocation = @"C:\Users\admin\Music\house_tex.wav";
player.Play();
//Graphics g = e.Graphics;
Graphics displayGraphics = e.Graphics;
int k = 0;
while (k < 500)
{
Pen p = new Pen(Color.Red);
SolidBrush b = new SolidBrush(Color.Yellow);
SolidBrush b1 = new SolidBrush(Color.Green);
//создаем объект - изображение, которое будет включать все, что нарисовано на форме
Image i = new Bitmap(ClientRectangle.Height,ClientRectangle.Width);
Graphics g = Graphics.FromImage(i);
g.Clear(Color.Aqua);
Thread.Sleep(200); //задержка на 300 миллисекунд
g.FillEllipse(b, k, 150, 30, 45);
g.FillEllipse(b1, k + 5, 165, 5, 5);
g.FillEllipse(b1, k + 20, 165, 5, 5);
g.DrawArc(p, k + 5, 175, 20, 10, 0, 180);
g.FillRectangle(b1, 0, 190, 500, 100);
k = k + 10;
//выводим на форму, созданное изображение
displayGraphics.DrawImage(i, ClientRectangle);
}
}
示例14: ProcessMessage
/// <summary>
/// <Message>
/// <MessageType>Info</MessageType>
/// <DateTime>20:12:00</DateTime>
/// <TeamId></TeamId>
/// <Category>Test</Category>
/// <Text>Dit is een bericht</Text>
/// <Forward>0</Forward>
/// <Synchronized>0</Synchronized>
/// </Message>
/// </summary>
public void ProcessMessage(string message)
{
try
{
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(message);
string messageType = xmlDocument.SelectSingleNode("Message/MessageType").InnerText;
string category = xmlDocument.SelectSingleNode("Message/Category").InnerText;
SoundPlayer soundPlayer = new SoundPlayer();
switch (messageType.ToLower())
{
case "info":
switch (category.ToLower())
{
case "success":
case "firstplace":
soundPlayer.Stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(_succesList[_random.Next(0, _succesList.Count)]);
soundPlayer.Play();
break;
}
break;
case "error":
soundPlayer.Stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(_errorList[_random.Next(0, _errorList.Count)]);
soundPlayer.Play();
break;
}
}
catch
{ }
}
示例15: pictureBox1_Click
private void pictureBox1_Click(object sender, EventArgs e)
{
//Creates a sound playback object
SoundPlayer bitch = new SoundPlayer("bitch.wav");
//Plays "Bitch I'm lil B"
bitch.Play();
}