无法加载音乐文件 [英] Cannot load music file

查看:109
本文介绍了无法加载音乐文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将music(mp3)文件放在音乐文件夹中,并在游戏类中创建了一个Song song;对象. 然后,我在ContentLoad方法中进行了song = Content.Load<Song>("music file name here")并进行了MediaPlayer.Play(song). 但这给了我一个错误:

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.

我听说Monogame没有内容管道,但是我不明白它是什么.谁能解释我应该怎么做才能播放音乐文件?

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?

推荐答案

您可以找到一个教程(由我撰写),该教程准确地解释了如何在Monogame中使用声音

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:

  • 使用XNA创建一个新的Game项目.
  • 将所需的声音文件添加到内容项目中.
  • 编译.
  • 转到输出文件夹,然后将声音xnb文件复制到您的单人游戏中(将其添加到Content文件夹中).
  • 将其属性更改为内容"和如果更新则复制",以使其起作用.

图像已选择spritefont,但对声音效果也是如此.

The image has a spritefont selected, but the same applies to sound effects.

然后,您可以像在典型的XNA游戏中一样使用它.

Then you can use it as you would in a typical XNA game.

截止到今天,我还无法找到另一种无需XNA来加载它们的方法.精灵字体也是如此.您需要使用XNA提供的Content项目来生成xnb文件.

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.

请记住,由于 XNA刷新,您可以在VS 2012+和Windows 8上安装XNA而不会出现问题.

Remember that you can install XNA on VS 2012+ and Windows 8 without a problem thanks to XNA Refresh.

我上次使用Monogame(2014年9月)时还需要添加一件事;从Monogame网站下载的模板中存在一个错误,该错误不允许播放任何声音效果(歌曲,效果,实例等);这样就不会发生任何错误. 当时的解决方案是使用Nuget下载Monogame模板.

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.

这篇关于无法加载音乐文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆