首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Greenfoot中的音量控制

Greenfoot中的音量控制
EN

Stack Overflow用户
提问于 2018-04-18 11:36:14
回答 1查看 242关注 0票数 0

我正在尝试创建一个简单的绿色脚mp3播放器,并使用按钮来控制音量。我有一些代码,我认为应该可以工作,但它不是。我不确定问题出在哪里。我试着增加音量,当向上按钮被按下时,音量减少1,当向下按钮被按下时,我对编程相当陌生,所以任何帮助都会很大。谢谢!

代码语言:javascript
复制
    public class Play extends Actor
{
public GreenfootSound sound = new GreenfootSound("AdventureOfaLifetime.mp3");
private boolean off = true;
int currentVolume = sound.getVolume();

Up volumeUp;
Down volumeDown;

/**
 * Act - do whatever the Play wants to do. This method is called whenever
 * the 'Act' or 'Run' button gets pressed in the environment.
 */
public void act() 
{    
    if (Greenfoot.mouseClicked(this) && off)
    {
        setImage("Pause.png");
        sound.play();
        off = false;            
    }
    else if(Greenfoot.mouseClicked(this) && !off)
    {
        setImage("Play.png");
        sound.pause();
        off = true;
    }    

    if(volumeUp.clicked)
    {
        if(currentVolume < 100)
        {
            currentVolume = currentVolume + 1;
            sound.setVolume(currentVolume);
        }
    }

    if(volumeDown.clicked)
    {
        if(currentVolume > 0)
        {
            currentVolume = currentVolume - 1;
            sound.setVolume(currentVolume);
        }
    }
}

 public class Down extends Play
{
static boolean clicked = false;

/**
 * Act - do whatever the Down wants to do. This method is called whenever
 * the 'Act' or 'Run' button gets pressed in the environment.
 */
public void act() 
{
    if (Greenfoot.mouseClicked(this))
    {
        clicked = true;
    }
    else
    {
        clicked = false;
    }        
}     


public class Up extends Play
{
static boolean clicked = false;

/**
 * Act - do whatever the Up wants to do. This method is called whenever
 * the 'Act' or 'Run' button gets pressed in the environment.
 */
public void act() 
{
    if (Greenfoot.mouseClicked(this))
    {
        clicked = true;
    }
    else
    {
        clicked = false;
    }  
}    
EN

回答 1

Stack Overflow用户

发布于 2018-04-18 11:52:13

我有点事要做。我只是将currentVolume设置为50,然后将if语句更改为currentVolume += 1;currentVolume -= 1;。这可能不是最好的解决方案,但至少它是有效的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49890760

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档