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.
Related
I have a quick question.
I am using the "video" tag on my web page to display video from my server say "/videos/myvideo.mp4
Video is playing fine.
The issues is when I try to delete the video from some other code (server side)
via File.Delete(physical path) I am getting "File in use" error.
Is this a known issue?
How can I delete the video physically if someone is playing that video on his page at the same time?
I have had a similar problem when trying to rename a file, using C# on Windows 7. I do have a feeling that the problem is not as severe now as it was when I wrote that code. I don't know if some Windows 7 patch has fixed it.
Some things to try:
Ensure your OS is fully patched.
Ensure the file is Close'd before attempting the delete.
Set any variables that use the file to null.
Dispose any variables that use the file.
If you are absolutely sure nothing is holding the file open, you
might need to write a loop to keep trying the Delete, say every few
seconds. (Horrible fudge, it was the only thing that worked for me.)
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.
In my current game, modding is a HUGE part of the game. It took me a while to develop a good system of loading modded content into the game, but I finally settled on a method, and I would like to keep it if possible.
How I'm handling modded content
In the game's content folder (C:/Users/username/4X), there is a Mods folder. Each mod will have it's own folder inside of the Mod directory. The game goes through a file (Rather, it will. I haven't implemented it yet), and figures out which Mod directories that it's going to load. After it's figured that out, it loads all of the content into the game (I can explain in more detail if its pertinent to the topic, I just don't wan't to use up space on unnecessary things).
So what's your problem?
Well, the mods will all have raw resources (.fbx, .wav, .mp3), and since I can't load anything but XNB files, I have absolutely no idea how to load the mod's content. Well, I take it back, I've been thinking of a few solutions but I really don't know which is more practical, or if there is a better way of doing this.
First, I thought about borrowing some code from the Pipeline application, and building all of the mod's content the first time it was loaded, but I don't fully understand the Pipeline's code, and I didn't want to mess up something by partially implementing it.
Next, I thought about requiring mod creators to use the Pipeline to build their content before they release their mods, but that seemed kind of unprofessional, since I want to have a Mod Creation Engine that has all of the tools bundled together. Which brings me back to using some of the Pipeline's code and embedding it in the engine, but then I have the same issue as my last idea.
And finally, I thought about just loading raw content. But there's an obvious flaw with that idea.
So I guess what I'm asking is:
How can I load raw content? That is, content that hasn't been built into XNB Files
If not, how can I start learning about the code that makes the Pipeline application tick, since I'll probably have to use some of it's code?
You can actually load some raw content directly with MonoGame. For example:
var texture = Content.Load<Texture2D>("raw.png")`
should work if you've got the PNG file in the Content directory and set it's properties to Content / Copy if newer.
However, please note that this will only work for some content and some platforms. I know PNG files work, WAV files work (but they must be mono 44khz I believe) and I'm pretty sure I got MP3 files to work once.
You'll probably run into issues with FBX files and sprite fonts. There's nothing stopping you from bypassing the content manager and loading these yourself though. I've done this before with great success.
Oh, and the other thing I should mention, take a look at the TitleContainer.OpenStream method. This is a way to read a file without writing the platform specific code yourself.
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.