This might seem like a very basic question, but not even by researching for hours I could find out what I did wrong.
I tried to write a simple console application that is supposed to play a sound from a resource, and this is my code:
using System;
using Microsoft.DirectX.DirectSound;
namespace AudioPlayer
{
class Program
{
static void Main()
{
Console.WriteLine("Playing...");
Device device = new Device();
SecondaryBuffer buffer = new SecondaryBuffer(AudioPlayer.Properties.Resources.AudioFile, device);
// AudioPlayer.Properties.Resources.AudioFile returns a stream
buffer.Play(0, BufferPlayFlags.Default);
Console.WriteLine("Finished");
Console.ReadKey(true);
}
}
}
But all I get is a console window with no text although at least "Playing..." should be printed, and there is no sound as well.
I am using Visual Studio 2015 which provides the option to pause an application, and if I do that, it tells me that all threads are currently processing external code. Considering that, I assumed that my program got stuck while creating the device or the buffer, but then again Console.WriteLine("Playing...");
seems remaining unexecuted!
Additional inforamtions:
.NET framework version 4.6
32-bit program
sound file format: WAV
codec: MPEG-1 Audio Layer 3 (MP3)
It would be really great if someone could explain where I failed! And sorry if this is a duplicate or if I made a really really silly mistake, but after all the time spent on this, I still can neither figure out how to solve it, nor find an already existing explanation.