【问题标题】:C# How to Stop a WindowsMediaPlayer mp3 "Soundtrack" from playing that is on a different formC# 如何阻止 Windows Media Player mp3“原声带”以不同的形式播放
【发布时间】:2019-01-19 12:03:59
【问题描述】:

我的项目是一个 Windows 窗体游戏,在后台播放 mp3 配乐,配乐完全取决于玩家所处的游戏状态/形式。目前我从启动屏幕播放“Introthemetune”配乐,但是当用户最终进入“玩游戏状态”/新游戏我需要“Introthemetune”停止,以便另一个人能够不受干扰地玩。

我知道如何使 Introthemetune 在使用 Introthemetune.controls.stop() 实例化的同一 Form 内停止播放。我也尝试从新实例化的表单中访问该类,但没有成功。

我的 LaunchScreen 表单和实例化类中的代码 -

WindowsMediaPlayer Introthemetune = new WindowsMediaPlayer();

    public LaunchScreen()
    {
        this.Opacity = 0;
        InitializeComponent();
        Introthemetune.URL = "Finalised Game Soundtrack.mp3";
    }

...

private void Gamescreen_Load(object sender, EventArgs e)
    {

     Introthemetune.controls.play();
    }

我需要此代码来停止在此表单之外播放。

【问题讨论】:

    标签: c# winforms properties windows-media-player


    【解决方案1】:

    如果在显示第二个表单之前无法手动停止它,那么最简单的方法是在表单中将Introthemetune 定义为public static 变量,例如MainForm。然后你可以从任何地方访问它,比如MainForm.Introthemetune.controls.stop()

    【讨论】:

    • 你是个传奇人物,却没有意识到我们要全球化的课程。非常感谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多