Cannot load music file

柔情痞子 提交于 2020-01-06 10:18:31

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/28517999/cannot-load-music-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!