Csharp/CSharp Tutorial/Development/SoundPlayer — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 12:14, 26 мая 2010
Play a wav file by using SoundPlayer
using System;
using System.Windows.Forms;
using System.Media;
public class MainClass
{
public static void Main() {
OpenFileDialog openDialog = new OpenFileDialog();
openDialog.Filter = "WAV Files|*.wav|All Files|*.*";
if (DialogResult.OK == openDialog.ShowDialog())
{
SoundPlayer player = new SoundPlayer(openDialog.FileName);
try
{
player.Play();
}
catch (Exception)
{
MessageBox.Show("An error occurred while playing media.");
}
finally
{
player.Dispose();
}
}
}
}
Play the sound associated with the Asterisk event
using System;
using System.Windows.Forms;
using System.Media;
public class MainClass {
public static void Main() {
// Play the sound associated with the Asterisk event
SystemSounds.Asterisk.Play();
}
}