Clip.stop();虽然方法被调用,但在方法中调用时不会工作

问题描述 投票:0回答:1

我想创建一个游戏,我已经完成了制作主菜单和关卡选择菜单。在我的主菜单中,我有一首来自SharedClass的歌曲。我的主菜单中还有一个按钮可以启动视频。视频按计划开始,但我无法停止音频,虽然我创建了一个方法,在我的共享类中包含剪辑停止,如果调用方法,我使用System.out.println测试,情况也是如此。我真的不知道为什么音频不会停止。任何帮助表示赞赏。

My Shared Class

 public void stopAudio() {
clip.stop();
System.out.println("Test");
isPlaying = false;
}

My Video Class Where the video starts and the method from the sharedclass is being called which is supposed to stop the audio

SoundSharedInstance soundSharedInstance = SoundSharedInstance.getInstance();
    soundSharedInstance.stopAudio();

My Main Menu Where the audio starts

SoundSharedInstance soundSharedInstance = SoundSharedInstance.getInstance();
    if (!soundSharedInstance.isPlaying()) {
        soundSharedInstance.createAudio(new File("sounds//opening1.wav"));
        soundSharedInstance.startAudio();
        System.out.println(soundSharedInstance.isPlaying());
    }
java javasound
1个回答
0
投票

据我所知,你对Clip的基本调用很好。我打算冒险说这个问题是由于静态SoundSharedInstance类与实际情况的管理不当引起的。对我来说,尝试解决这个问题比我有时间做更多的工作,但是你可以做一些有助于证实这个理论的测试。

你有一个检查,你在stopAudio方法输出“测试”。你确定参与的clip和正在播放的是同一个吗?

例如,它可以帮助输出hashID(在clip的实例化时,它的开始和停止,也可能在调用isPlaying方法时stopAudio的值。如果它告诉你“假”我不会感到惊讶即使你听到它,这也表明涉及多个实例。

© www.soinside.com 2019 - 2024. All rights reserved.