public override void Execute() { // Create a LowLevelSystem - this is the most basic system and has no support for FMOD studio projects using (var system = new LowLevelSystem()) { // Set up the demo to call update on the system Pump(system); // Create a new sound object using (var sound = system.CreateSound(name: GetContentPath("Front_Center.wav"), mode: Mode.LoopNormal)) { Console.WriteLine("Playing sound, Length {0}ms", sound.GetLength(TimeUnit.Milliseconds)); // Begin playing the sound, this returns the "channel" which is playing this sound var channel = system.PlaySound(sound, null, false); // Wait until any key is pressed WaitForKeypress(() => Console.WriteLine("Position {0} ms", channel.GetPosition(TimeUnit.Milliseconds))); // Stop the sound playing channel.Stop(); Console.WriteLine(channel.IsPlaying); } } }
private Channel PlaySound(LowLevelSystem system, Sound sound) { Console.WriteLine("Playing"); //Play the sound, but start it paused var channel = system.PlaySound(sound, null, true); //Set a callback on the channel, this is called for all events on the channel channel.SetCallback((type, data1, data2) => { //When we get the "end" event start playing the next sound if (type == ChannelControlCallbackType.End) { Console.WriteLine("Callback: Finished, playing next sound"); PlaySound(system, LoadNextSound(system)); } }); //Unpause the channel channel.Pause = false; //Save this channel _currentChannel = channel; return(channel); }
public void TestMethod1() { using (var system = new LowLevelSystem(preInit: a => { a.Output = OutputMode.NoSound; })) { //Load a sound to play var sound = system.CreateStream(name: "Content/Front_Center.wav", mode: Mode.Default); // Begin playing the sound var channel = system.PlaySound(sound, null, false); bool flag = true; channel.SetCallback((type, data1, data2) => { if (type == ChannelControlCallbackType.End) { //Now that the sound is done, dispose it //With issue #23 this should crash on mono sound.Dispose(); flag = false; } }); //Loop until the flag is set to false while (flag) { system.Update(); } } }
public override void Execute() { // Create a LowLevelSystem - this is the most basic system and has no support for FMOD studio projects using (var system = new LowLevelSystem()) { // Set up the demo to call update on the system Pump(system); // Create a new sound object using (var sound = system.CreateSound(name: GetContentPath("test.wav"), mode: Mode.Default)) { // Begin playing the sound, this returns the "channel" which is playing this sound var channel = system.PlaySound(sound, null, false); channel.SetCallback((type, data1, data2) => { if (type == ChannelControlCallbackType.End) { Console.WriteLine("Callback: Finished playing sound"); } }); //temp: Force GC collection to test callback handling GC.Collect(); // Wait until any key is pressed WaitForKeypress(() => { //temp: Force GC collection to test callback handling GC.Collect(); var pos = channel.GetPosition(TimeUnit.Milliseconds); if (pos.HasValue) Console.WriteLine("Position {0}ms", pos.Value); }); // Stop the sound playing channel.Stop(); } } }
public override void Execute() { // Create a LowLevelSystem - this is the most basic system and has no support for FMOD studio projects using (var system = new LowLevelSystem()) { // Set up the demo to call update on the system Pump(system); // Create a new sound object using (var sound = system.CreateSound(name: GetContentPath("test.wav"), mode: Mode.LoopNormal)) { // Begin playing the sound, this returns the "channel" which is playing this sound var channel = system.PlaySound(sound, null, false); // Wait until any key is pressed WaitForKeypress(() => Console.WriteLine("Position {0} ms", channel.GetPosition(TimeUnit.Milliseconds))); // Stop the sound playing channel.Stop(); Console.WriteLine(channel.IsPlaying); } } }