【问题标题】:Play Music before and after another Sound runs, starting at the point it stopped在另一个声音运行之前和之后播放音乐,从它停止的点开始
【发布时间】:2016-05-18 20:06:29
【问题描述】:

我目前正在为我的小游戏制作选项菜单。例如,该菜单可以启用音乐和声音。

如果您启用音乐和声音,会发生以下情况:

  1. 播放音乐
  2. 如果你赢了,就玩一场胜利的声音
  3. 安静。

应该发生什么: 1.播放音乐 2.如果你赢了就开始声音 3. 从停止的地方播放音乐

现在,我检查是否选中了复选框,如果是,则播放音乐:

else if (enable_music.Checked && enable_sound.Checked && download_no)
        {
            //Store the State of the Application
            Properties.Settings.Default.enable_music = true;
            Properties.Settings.Default.enable_sounds = true;
            //Load Music
            SoundPlayer snd = new SoundPlayer(fileName_standard);
            //We need to call the Sound only if we won or lost, so we save the Preference and call it in the Winscreen
            Properties.Settings.Default.enable_sounds = true;
            //Play the files
            snd.Play();
            Close();
        }

只有在显示 Winscreen 时才会播放获胜的声音。

所以我想把音乐放到一个新的方法里,以后再调用:

private async Task PlayMusic(SoundPlayer snd)
    {
        snd.Play();
    }

呼叫:

else if(enable_darkmode.Checked && download_no)
        {
            SoundPlayer snd= new SoundPlayer(fileName_dark);
            PlayMusic(snd);
            Close();
        }

但是,如果另一个文件开始播放,正常的音乐就会停止。 那么,如果正在播放另一个文件,如何让音乐暂停,如果文件停止播放,如何恢复音乐呢?

谢谢!

【问题讨论】:

    标签: c# winforms audio


    【解决方案1】:

    使用单独的线程来运行音乐播放的单独实例,因此 orugunal 可以在第二个运行时暂停而不会中断暂停的音频

    【讨论】:

    猜你喜欢
    • 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
    相关资源
    最近更新 更多