5
I’m creating a game in C# (Aplication console) and I need to put a background music, as I do?
5
I’m creating a game in C# (Aplication console) and I need to put a background music, as I do?
5
As an example from the documentation of MSDN you can use something like:
Matter:
using System.Media;
And use it like this:
SoundPlayer player = new SoundPlayer();
player.SoundLocation = Environment.CurrentLocation + "typewriter.wav";
In case you only need to set the audio location on SoundLocation
and then execute .Play
(runs asynchronously, to charge synchronously, which can lock the app depending on the case, use PlaySync
):
try {
player.Play();
} catch (Exception ex) {
Console.WriteLine(ex.Message); //Somente um exemplo exibir erros em caso de falha, pode modificar como desejar
}
2
The question does not give details, but the basics would be more or less this:
var player = new SoundPlayer("NomeDoArquivo.wav");
player.Play();
0
First include the using System.Media;
at the beginning of the code, after that, to differentiate from the other responses, you can include a Resource of a Sound (go to Project > Properties... > Resources > click to create a Resources file > look for the Add an Audio corner) and then play it to Soundplayer.
public static void Main(string[] args)
{
SoundPlayer soundPlayer = new SoundPlayer(Properties.Resources.SimpleSound);
soundPlayer.Play(); // Para começar o som normalmente.
soundPlayer.PlayLooping(); // Para começar o som e ficar repetindo.
soundPlayer.PlaySync(); // Para começar o som e só ir para a próxima linha quando parar de tocar.
}
This text is familiar, could you name the source from where you got it? Don’t copy information from where you don’t know if you can copy, and if you can copy, always cite the source. This is being discussed here: http://meta.pt.stackoverflow.com/q/5430/101
Browser other questions tagged c# .net áudio
You are not signed in. Login or sign up in order to post.
since already I am grateful my friend, I am programming a very short time.
– Wilson Dayvis
@Wilsondayvis perhaps could mark an answer as accepted.
– durtto