如何暂停剪辑?爪哇 [英] How do i pause a clip? Java

查看:130
本文介绍了如何暂停剪辑?爪哇的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个工作正常的音乐播放器,但我想添加一个播放/暂停按钮.我已经设置了按钮以及所有其他功能,但是我不知道实际暂停剪辑的代码.

I have a music player that works perfectly fine but i want to add a play/pause button. I have set the button up and all that but i don't know the code to actually pause the clip.

这是我的代码:

        try{
        File f = new File("songs/mysong.wav");
        Clip clip = AudioSystem.getClip();
        AudioInputStream ais = AudioSystem.getAudioInputStream(f);
        clip.open(ais);
        playing = true;
        if(MusicPlayer.pause)
        {
            clip.stop(); // <- Doesnt stop the song
        } 
        clip.loop(Clip.LOOP_CONTINUOUSLY);

    }catch(Exception exception){System.out.println("Failed To Play The WAV File!");}

提前谢谢!

推荐答案

您需要在clip.open(ais)之后调用clip.start();,然后clip.stop()将起作用.

You need to call clip.start(); after clip.open(ais) then clip.stop() will work.

这篇关于如何暂停剪辑?爪哇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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