I'm trying to load sound into my game. I downloaded an .mp3 sound (a second long) and tried to load it both as Song and as SoundEffect, but it didn't work, so I tried loading the same sound but as .wav and I was able to load it as a SoundEffect. The problem is that the sound that is coming out sounds like static noise.
I looked a bit into this and found out I need to load sounds as .xnb files, so I downloaded "XNAContentCompiler" project and tried to compile the sounds causing a PInvokeStackImbalance error.
So I found this thread:
http://xboxforums.create.msdn.com/forums/p/65519/65519.aspx
Saying I can ignore this and continue.
The xnb file fails to be created when I try to convert the .wav files, saying it is 24-bit audio and I may only use 8 to 16 bit.
So I tried to compile the .mp3 file and it succeed, creating a 1k file that I still cannot load not as a Song and not as SoundEffect.
I'm now completely lost on this and can no longer understand what I need to try to load and what is a different problem completely, and I would love some explanations.
Audio files, as any content file, needs to be converted using the XNA Content Pipeline, it's easier if you use a Visual Studio 2010 version with XNA installed in it to convert your contents, so you can copy that .xnb file in your Monogame project.
I think you already know that you have to change its properies to "Copy always" and "Content" to use it in Monogame.
If your problem is the bit resolution, you can always use an audio converter, you can find them online, too.
Anyway, it's better if you use .mp3 as Song and .wav as SoundEffect.
Related
I added some audio files into wwwroot/audio, used them dynamically in different views, then I wanted to make some changes. After removing the first file (UserAudio001.wav) and renaming another file to UserAudio001.wav, after debugging in application there is still the older version of the audio. I removed all of the files and debugged the app, the UserAudio001.wav was still playing.
It says that the source of the file is audio/UserAudio001.wav, it is possible to play sound from the url localhost:44329/audio/UserAudio001.wav, but from the Solution Explorer the audio folder is empty. The localhost:44329/audio url also says that there is nothing in audio folder. Cleaning the solution didn't work. Where can I find these older static files? I can't replace them with the new ones.
I have included a SpriteFont asset and an mp3 asset in my MonoGame cross platform project, the strange thing is that the the game compiles and runs fine on the iOS simulator but whenever I try to build the game on Android I get warnings like this for the files in the bin directory and in the content directory
/Users/edward/Library/Mobile Documents/com~apple~CloudDocs/apps/Xamarin/Android/Radiant/Android/Content/lights.mp3:
Warning XA0101: #(Content) build action is not supported (XA0101) (Radiant.Droid)
And when I try and run the game, I get a
Could not load score asset as a non content file
I have tried many things such as changing the build actions of various files but nothing has worked.
This could be an issue of upper case and lower case file names. I've run into this issue before.
If it's not that, you can extract the Android *.apk file like a *.zip file to see what files are actually in there. This can seriously help on figuring out why files aren't being loaded with android.
To Extract
Create a copy of your *.apk file, so that you're not modifying the original.
Change the file extension too *.zip.
Now right click and extract like any other *.zip file.
You can then go in and explore the folder hierarchy to see what files are being included.
Check your Asset folder to see if the file you're looking for is there or not.
Hope this helps.
Are you using the monogame content builder or are you trying to load them in directly as .mp3 .png or whatever?
If you aren't using the content builder everything has to be .xnb on android.
I'm learning Xna, and I have some trouble with loading non .xnb file formats.
I don't know why, but Xna searches only for .xnb files.
Here is my code:
Effect simpleColorEffect;
simpleColorEffect = Content.Load<Effect>("SimpleColor");
I saw some solutions for this, but they didn't work.
How can i solve this?
I would thank you any advices.
Put specific file into Content folder and make sure that content processor for that file is set to Effect - XNA framework.
I am trying to program an automatic Resource Loader for my project and so it is going well. But I am stuck on the loading of the sprites. I used this for checking the file exists
if (File.Exists(contentManager.RootDirectory + "/Sprites/" + spriteName + ".png"))
However it never finds the file, even though the file exists in the Content of the project. I have checked the folders and found that the .pngs are replaced by .xnb files. So I tried changing the file extension and then was given an error in the Sprite Load function
return contentManager.Load<Texture2D>(assetName);
It only happens if I change it from being a typical image file (png, bmp, etc). Can someone explain why this is the problem and how I can get around this? I have had no experience in the xna file extensions and can not find the answers I need. What I want is to load a new image into the project providing it exists in the Content Directory after compile
While on the topic, will the Sounds and Music be effected by the Compiler?
When you use a content project, the resources are imported, processed and write to disk again as xnb files.
If you want to dynamically load resources you have to compile files on the fly through the content builder or avoid using the content project.
Microsoft provides examples like this to load content dynamically: http://xbox.create.msdn.com/en-US/education/catalog/sample/winforms_series_2
if you want to distribute the application, the runtime xna is not enoigh, you need full xna framework and visual studio installed to work.
if you want the original files in the content project, you have to change their "copy to output folder" property to "copy always", and realize that the compiled results will be at "project folder\bin\debug\content"
I created a XNA Game Library Project that loads several sound and image files. But for the project to run, I need to convert these to XNB files. I am wondering, how do you go about doing that? Thanks!
The XNA Content Pipeline takes care of much of that for you. If you are using the XNA Game Studio, importing many types of content files will automatically hook up the right pipeline (which you can then edit).