I want to create an application where i can play a .wav file after the input matches a certain number.
Now I've only come up across threads on how to check if the input is only numbers etc. but i couldn't find any solution yet for my problem.
Here's some code I'm currently using:
if(fortwenty_Tb.Text.Equals("420"))
{
player.Play();
}
The application works, but the sound isn't playing.
I've already checked if the .wav file was faulty, but it isn't since it does work after i tried playing it with a button controller.
First of all, you have to use debugger and breakpoints to ensure that Play() is called. Then you have to check volume of player, volume of your application in windows mixer, and, additionaly, file integrity and codec.
Related
I have written my own .DAV file player in C# for individual use. There is too much code to attach if I would have to explain what it exactly is. How can I get the .DAV file length in time to my player?
There is no meta-data like time-length for dav files in windows, and I can't find anything in Google. I will add that I can not count it on when file was created and as last modified. I was thinking about making a counter on file start in the player in seconds, but it is not what I mean. I would like to show how long the file is in time, and place it beside my progress bar like every player should look like.
My player is using VLC libraries.
I have a connect four game which is fully completed, but to learn new stuff im trying to add sounds for when the counter drops in the hole, I cant understand why i keep getting FileNotFound exceptions when i have imported my sounds file to be both in the solution and in the debug file.
this keep crashing:
(new SoundPlayer("Clonk.mp3")).Play();
I have also tried .PlaySync() which gave me the same result
thanks guys!
The SoundPlayer only supports certain .wav files. Try converting your .mp3 file into a .wav and see if this fixes the problem for you.
System.Media.SoundPlayer(string wav).Play();
I want to load a song with the Song.FromUri() method, it works with some files, doesn't work with others. All i could find out is that if i try to play a song from a downloaded album, it won't play, but if i try to play one randomly google'd and downloaded, it plays well. I tried to place the "wrong" file to the Content folder and load it with Content.Load<Song>("filename") method, it perfectly plays, but i can't do it that way since it would be a player application, and the user has to choose own files. Any advice?
No, there is no exception, it simply does nothing. Anyway, i made another way.
I'm trying to get background music going for my XNA game, but the options in XNA all require that the audio files be converted to .wav and included as project resources. This doesn't work for me for two reasons. First, .wav files are enormous, and have no real benefit to the user. Second, the user would be unable to have a folder of mp3s to substitute, should they prefer their own music. What are my options for playing mp3s that are not actually part of the project?
After doing a lot of searching, I finally found this thread on the App Hub forums which gave me a solution.
You can use Song.FromUri to load a song, then use MediaPlayer.Play(song) to play said song.
Uri songPath = new Uri("Songs/song.mp3", UriKind.Relative);
Song song = Song.FromUri("song", songPath);
MediaPlayer.Play(song);
In your question you said (quite obviously) that you don't want to use MediaPlayer, but it seems as though the reason why is because you would first need to convert the song and it needs to be included in the project resources. With this, the song would only need to be in a "Songs" directory (which would be located in the same directory as the executable).
Using the SoundEffect class wouldn't work either, since you'd have to use TitleContainer.OpenStream, which liked to complain when I tried it.
I'm trying to index every music file in a folder and play them at random (without repeating) with the default application on my system. For example:
ogg - itunes
mp3 - WMP
mp4 - quicktime
Are there tutorials that will help me with this? Thanks!
Well, once you have a list of files, if you want to come up with a (pseudo)-random permutation of them, what you want is a shuffle algorithm, like Knuth-Fisher-Yates.
If you have a single filename and you want to open it with the default application, you can probably use:
System.Diagnostics.Process.Start(mp3FileName);
See also the MSDN documentation on Process.Start.
This will behave equivalently to just double-clicking on the files in whatever order the shuffle comes up with. Depending on your media player, that may be good enough. However, unless you somehow know how long each media file is, you won't know how long to wait before starting the next one, and I don't think there's any way to wait for the music player to finish playing the media file without having special-case code specific to each player.
You may be able to use the Verb property of the ProcessStartInfo object to select "Enqueue" or something similar, which may do exactly what you want. Again, MSDN has some additional information on ProcessStartInfo.Verb that may be helpful to you.