2009-01-29 00:18:34 +08:00
|
|
|
using System;
|
|
|
|
using System.Threading;
|
|
|
|
using SFML;
|
|
|
|
using SFML.Audio;
|
|
|
|
|
|
|
|
namespace sample_sound
|
|
|
|
{
|
|
|
|
static class Program
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// The main entry point for the application.
|
|
|
|
/// </summary>
|
|
|
|
static void Main(string[] args)
|
|
|
|
{
|
|
|
|
// Play a sound
|
|
|
|
PlaySound();
|
|
|
|
Console.Clear();
|
|
|
|
|
|
|
|
// Play a music
|
|
|
|
PlayMusic();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Play a sound
|
|
|
|
/// </summary>
|
|
|
|
private static void PlaySound()
|
|
|
|
{
|
|
|
|
// Load a sound buffer from a wav file
|
2009-07-17 16:11:03 +08:00
|
|
|
SoundBuffer buffer = new SoundBuffer("datas/sound/footsteps.wav");
|
2009-01-29 00:18:34 +08:00
|
|
|
|
|
|
|
// Display sound informations
|
|
|
|
Console.WriteLine("footsteps.wav :");
|
2009-07-17 16:11:03 +08:00
|
|
|
Console.WriteLine(" " + buffer.Duration + " sec");
|
|
|
|
Console.WriteLine(" " + buffer.SampleRate + " samples / sec");
|
|
|
|
Console.WriteLine(" " + buffer.ChannelsCount + " channels");
|
2009-01-29 00:18:34 +08:00
|
|
|
|
|
|
|
// Create a sound instance and play it
|
2009-07-17 16:11:03 +08:00
|
|
|
Sound sound = new Sound(buffer);
|
|
|
|
sound.Play();
|
2009-01-29 00:18:34 +08:00
|
|
|
|
|
|
|
// Loop while the sound is playing
|
2009-07-17 16:11:03 +08:00
|
|
|
while (sound.Status == SoundStatus.Playing)
|
2009-01-29 00:18:34 +08:00
|
|
|
{
|
|
|
|
// Display the playing position
|
|
|
|
Console.CursorLeft = 0;
|
2009-07-17 16:11:03 +08:00
|
|
|
Console.Write("Playing... " + sound.PlayingOffset + " sec ");
|
2009-01-29 00:18:34 +08:00
|
|
|
|
|
|
|
// Leave some CPU time for other processes
|
|
|
|
Thread.Sleep(100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Play a music
|
|
|
|
/// </summary>
|
|
|
|
private static void PlayMusic()
|
|
|
|
{
|
|
|
|
// Load an ogg music file
|
2009-07-17 16:11:03 +08:00
|
|
|
Music music = new Music("datas/sound/lepidoptera.ogg");
|
2009-01-29 00:18:34 +08:00
|
|
|
|
|
|
|
// Display music informations
|
|
|
|
Console.WriteLine("lepidoptera.ogg :");
|
2009-07-17 16:11:03 +08:00
|
|
|
Console.WriteLine(" " + music.Duration + " sec");
|
|
|
|
Console.WriteLine(" " + music.SampleRate + " samples / sec");
|
|
|
|
Console.WriteLine(" " + music.ChannelsCount + " channels");
|
2009-01-29 00:18:34 +08:00
|
|
|
|
|
|
|
// Play it
|
2009-07-17 16:11:03 +08:00
|
|
|
music.Play();
|
2009-01-29 00:18:34 +08:00
|
|
|
|
|
|
|
// Loop while the music is playing
|
2009-07-17 16:11:03 +08:00
|
|
|
while (music.Status == SoundStatus.Playing)
|
2009-01-29 00:18:34 +08:00
|
|
|
{
|
|
|
|
// Display the playing position
|
|
|
|
Console.CursorLeft = 0;
|
2009-07-17 16:11:03 +08:00
|
|
|
Console.Write("Playing... " + music.PlayingOffset + " sec ");
|
2009-01-29 00:18:34 +08:00
|
|
|
|
|
|
|
// Leave some CPU time for other processes
|
|
|
|
Thread.Sleep(100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|