【问题标题】:MonoGame Mediaplayer plays only one songMonoGame Mediaplayer 只播放一首歌曲
【发布时间】:2015-03-25 03:08:01
【问题描述】:

我用:

    MediaPlayer.Play(song1);

播放歌曲。

那我用

    MediaPlayer.Play(song2);

播放第二首歌曲。但 Mediaplayer 仍然播放歌曲 1。我试图停止播放器并再次播放歌曲 2,但它不起作用。当我交换歌曲 1 和歌曲 2 时,它只播放歌曲 2。

编辑: 我有这门课:

public class SoundHelper
    {
        public static void PlaySong(Song song)
        {
            MediaPlayer.Stop();
            MediaPlayer.Play(song);
        }

        public static void StopSong()
        {
            MediaPlayer.Stop();
        }
    }

我用:

SoundHelper.PlaySong(Content.Load<Song>("Sounds/Songs/MenuTheme"));

在游戏开始时播放歌曲并且它可以工作。

然后我使用:

SoundHelper.PlaySong(Content.Load<Song>("Sounds/Songs/Battle"));

在战斗中播放下一首歌曲,然后从头开始播放 MenuTheme。

【问题讨论】:

    标签: xna


    【解决方案1】:

    你必须停止播放当前歌曲

    if (PlaySong1) {
         MediaPlayer.Stop();
         MediaPlayer.Play(Song1); 
    }
    else{
         MediaPlayer.Stop(); 
         MediaPlayer.Play(Song2); 
    }
    

    编辑

    • 您的代码看起来不错,请确保您只调用一次“SoundHelper”, 在加载菜单或战斗中。

    • 还不确定 MediaPlayser.Stop() 上的“try”和“catch”,但是 如果没有加载歌曲,可能会抛出异常。

    • 最好在“loadcontent”中加载歌曲。

      song1 = Content.Load&lt;Song&gt;("song1"); song2 = Content.Load&lt;Song&gt;("song2");

    • 也可能添加MediaPlayer.IsRepeating = true; 可以解决。 到目前为止我能记得的就这些了。

    【讨论】:

    • 没用。它再次播放歌曲 1
    • @petros 请给我们更多代码。加载两首歌曲以及尝试播放它们的部分。
    • 不幸的是它没有帮助。
    • 哦,我忘了说我正在使用 MonoGame。我刚刚检查过,它在干净的 XNA 中运行良好。但是我该怎么做才能让它在 MonoGame 项目中工作呢?
    • @petros 尝试获取最新版本的 MonoGame。我四处搜寻,发现他们在这种情况下有一个错误。 github.com/mono/MonoGame/pull/2946/files
    【解决方案2】:

    不幸的是,这似乎是 MonoGame 中的一个错误。有同样的问题。 使用 3.3 版,您的方法应该可行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多