Cannot load music file - c#

I put the music(mp3) file in the music folder and created a Song song; object in the game class.
Then I did song = Content.Load<Song>("music file name here") in the ContentLoad method and did MediaPlayer.Play(song).
But it gives me an error saying:
Could not load music asset
I tried making the "Copy to Output Directory" to "Copy always". But this also didn't solve the problem.
I heared about monogame not having a content pipe line, but I don't understand what it is. Can anyone explain what I should do to make my music file playable?

You can find a tutorial (written by me) explaining exactly how to use sounds in Monogame here.
But basically, all you need to do is:
Create a new Game project with XNA.
Add the desired sound file to the content project.
Compile.
Go to the output folder and copy the sound xnb file to your monogame one (add it on the Content folder).
Change it's properties to "Content" and "Copy if newer" so that it works.
The image has a spritefont selected, but the same applies to sound effects.
Then you can use it as you would in a typical XNA game.
As of today, I have not been able to find another way to load them without needing XNA. Same goes for sprite fonts. You need to generate the xnb files by using the Content project provided by XNA.
Remember that you can install XNA on VS 2012+ and Windows 8 without a problem thanks to XNA Refresh.
One more thing to add, the last time I used Monogame (September, 2014); there was a bug in the templates downloaded from the Monogame site that would not allow for any sound effect (song, effect, instance, etc) to be played; and this would happen with no errors being thrown.
The solution at that time was to download the Monogame templates by using Nuget.

Related

Content Pipeline not working despite file existing in expected locations

I've been trying to figure out why the content pipeline tool isn't allowing me to load textures and spritefonts.
My MainGame constructor:
public MainGame()
{
_graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content"; //Content folder
_graphics.SupportedOrientations = DisplayOrientation.LandscapeRight;
_textureAggregate = new TextureAggregate();
}
This is the error (ContentLoadException: The content was not found):
Finally, my project folder structure:
Now, the defaultfont.xnb is being created by Content.mgcb to the ~/Content/bin folder, I've just copy-pasted it to /Content attempting to get the project to recognize at least this one file. Note that the stream is working just fine (but I don't know if that's the right way to load textures now?).
I'm looking for anything else that I might not know about that requires configuration in order to get my project to recognize these files.
You should not be adding the content into the Content folder. Instead, you need to open your content pipeline tool (Content.mgcb). You can add the textures you need there instead by clicking "Add Existing Item".
As is turns out, I didn't correctly remember the details of installing monogame and xamarin, and had created the project as an openGL game (the little icon is the same after creation on a compromised system so I thought nothing of it).
I blame this on having just redeployed my dev environments and had managed to install the monogame pipeline tool but none of the templates, so searches for the monogame project template type went nowhere but I could still create the content project in the Content folder.
I happened across all the same classes and objects I needed to do basic work without getting compile-time errors via nuget.
So, if anyone else is having a real hard time with this, make sure you installed MonoGame and are working with the templates and didn't mistakenly create an opengl game like this idiot :)

Excluding Library folder from Git for Unity project causes scene to be lost

I've gone through all the recommended steps to prepare a Unity project for a Git repository following the directions here:
Unity Git - Ignore Library
I've correctly setup the .gitignore file etc.
However when I clone my newly created Git repo on a different machine I noticed that my scene, assets etc. are missing. The scripts seem to be there.
I noticed that when I copy over the Library folder the missing things (scene, assets) come back.
I'm assuming that there is something in the Library folder that just can't be ignored or that the "forcing assets to text" just isn't working properly.
I'm using Unity 5.3.5f1.
I'm still fairly new to Unity/Git etc. so I may have overlooked something obvious but I've followed all suggested directions.
Any help would be much appreciated.
apparently Unity has changed the Library Folder many times in Unity 4.X that folder could be ignored. Now, it seems not.
I did some tests and the huge junk of files are for my in the ShaderCache and this folder seemed to be fine to delete. The other Folders should not be touched.
https://forum.unity3d.com/threads/26-581-bin-files-in-library-shadercache-folder-can-i-delete-these.326312/
Fell into same problem with Unity 2020.3
Some research showed that was needed files LastSceneManagerSetup.txt, CurrentLayout-default.dwlt for scene. And EditorSnapSettings.asset, EditorUserBuildSettings.asset for game window, game view and UI.
Maybe, I miss some other settings, so I saved files in Library root and replaced /[Ll]ibrary/ with:
/[Ll]ibrary/APIUpdater/
/[Ll]ibrary/Artifacts/
/[Ll]ibrary/BuildPlayerData/
/[Ll]ibrary/PackageCache/
/[Ll]ibrary/PackageManager/
/[Ll]ibrary/PlayerDataCache/
/[Ll]ibrary/ScriptAssemblies/
/[Ll]ibrary/ShaderCache/
/[Ll]ibrary/StateCache/
/[Ll]ibrary/TempArtifacts/
/[Ll]ibrary/UIElements/
Scenes are not entirely missing, as you can simply load them from Assets/Scenes. Their original order in the scene hierarchy, however, is lost.
I did even more tests than Jimmy and found out the only required things from Library are StateCache folder and LastSceneManagerSetup.txt file (less than 2 kB total in my case). Everything else located in Library folder can be safely removed.
Save these two:
StateCache/
LastSceneManagerSetup.txt

XNA/MonoGame publishing game, could not load SpriteFont as non content file

I have finished making a game; however, when I try to publish it. It publishes fine but when launching the application it crashes
SpriteFont
It says that it could not find MyFont.xnb (which is a SpriteFont in the content folder)
When I go to my Program Files and look, the SpriteFont is nowhere in my solution. Why did it not build with the rest of the program?
In my application itself, I made sure to include the asset and it works fine if I run the program on my machine. It only crashes like this after I publish the application.
How do I fix this issue?
Try checking the properties for the file in whatever compiler you're using.
In visual studio for example :
Make sure Build Action is set to compile.
Make sure copy to output directory is set to anything but do not copy, which is the default for monogame in my experience.
Okay so I fixed my issue:
I made my XNB file Build Action set to: "Content" and "Copy always"
Then, when setting up the project to release I used InstallShield Limited Edition Deploy.
When asking me for which files to deploy, I made sure to select "Primary Output" "Content" and "Add File" -> "MyFont.xnb" and I added it in manually, that made sure it was ready to go.

MonoGame on linux failing to load effect assets

EDIT: The issue is now solved, I'm including the details here to help anyone else who runs into this, as it's not that simple to solve.
Basically, it comes down to updating using the develop branch.
The first step is to checkout the monogame develop branch, this will not include the thirdparty/libs submodule, so you need to also update this in order to be able to compile the sources.
After this, you can compile MonoGame.Framework.Linux.sln, and update the references in your project to point to the new dll files.
This will still not load effect files, unless they are created using an up-to-date version of the content processors, so you need to go to a windows computer, checkout the develop branch (and libs) - or copy them from your linux system - then compile MonoGame.ContentPipeline/ContentProcessors/MonoGameContentProcessors.sln
You need to update the reference to MonoGameContentProcessors.dll in your content project, you also need to rename the MonoGame.ContentPipeline\ContentProcessors\bin\Release\libmojoshader_32.dll file to simply libmojoshader.dll.
Once all of this is done, you can finally use it as intended - build the .xnb files from your .fx files and add them to the linux project.
Hopefully this information will be useful to someone.
=================================================
Original post:
I have just started out with MonoGame, and am trying to get a very simple application (rotating cube) to work on Windows and Linux - windows is not proving to be a problem, but I am having trouble getting my .fx files to work on Linux.
I have set up a "MonoGame Content Project", added the .fx file to it, selected the "MonoGame Effect" processor, set the build configuration to Linux - this all seems to work and i get a .xnb file in the output directory.
When I set up the Linux project, I copied the .xnb to the "Content" folder (the root directory is set accordingly) and used the following code to load the effect (same code as on windows):
CubeEffect = Content.Load<Effect>("Effect1");
CubeEffect.CurrentTechnique = CubeEffect.Techniques["Technique1"];
This then results in an application crash with this error:
Microsoft.Xna.Framework.Content.ContentLoadException: Could not load Effect1 asset!
Initially i assumed this to be a problem with file names, directory names, or some incorrect setting. However, i tried adding a .png file to the content folder and loading that:
Texture2D Tex = Content.Load<Texture2D>("bg.png");
This works perfectly well (checked the properties of the Texture2D in the debugger, and it has correct details for the file).
Have i missed a step somewhere when converting the shader file? Is there some really obvious thing that I'm not seeing?
If not, does anyone have any clue why it would act like this, or some way to get a more detailed error from it, like an actual reason for it not being able to load the asset?
EDIT: Having looked at the point in the disassembly where it actually throws the error, it seems that it finds the file, but doesn't recognise it as any valid resource type - could this be some kind of version/compatibility issue?
This is a very common problem when trying to load shaders into Monogame.
I tried, and failed to be able to load my custom shader into the Monogame framework.
You need to compile from the develop3d branch, and not the official release. You also need to convert your HLSL shader into a MojoShader compatible syntax. Then you need to either load the effect from the Monogame Content importer (which needs to be configured manually), or add your shader as an embedded resource and load it into your project in order to use it.
I have never been able to actually pull this off myself. From my readings online, this particular part of the Monogame framework is not quite ready for primetime yet.
Here is some information on it. They really didn't provide much information on this as I suspect they know it is very problematic:
https://github.com/mono/MonoGame/wiki/Effects-And-Shaders

XNA C# - Manually create Content folder and adding assets

I've been trying to use XNA framework along with Visual Studio 2012. Since the xna framework is not yet compatible with Visual Studio 2012 I had to set it manualy.
Yet, I managed to succesfully import xna references and create default game methods allowing me to run my program.
The problem came when I tried to add texture to my project and load it. I manually created a "Content" folder in which I added my textures following msdn documentation at http://msdn.microsoft.com/en-US/library/bb313966(v=xnagamestudio.30).aspx
The problem is, since it's not XNA game project I wont have the properties window showing my texture file as a texture but just as a resource file.
And the following code:
Load<Texture2D>("GrassTexture");
Will systematically lead to an error file not found.
I've set my ContentManger as it follows:
ContentManager.RootDirectory = "Content";
Does anyone know how to properly set the content folder ?
I had this problem too, but there is a opportunity to enable the xna game project for vs 12.
Look here: https://stackoverflow.com/a/10881007/1780038

Categories