简体   繁体   中英

Change volume java using jlayer?

I've searched and read another topics but i still can't solve my problems. I had one java main class and one java jframe. I wanna add jslider to change volume in my mp3 player. What should i do?

my_player2_func

class my_player2_func{ static Player player;

static void play() {
    try {
        FileInputStream fe = new FileInputStream(my_player2_main.str);
        player = new Player(fe);
    } catch (Exception ex) {
        System.out.println(ex);
    }

    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                player.play();
            } catch (Exception ex) {
                System.out.println(ex);
            }
        }
    }).start();
}     

static void stop() {
    if (player != null)
        player.close();
}    }

my_player2_main

public my_player2_main() {
    initComponents();     
}
static String str;                              

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    my_player2_func.play();
}                                        

private void jSlider1StateChanged(javax.swing.event.ChangeEvent evt) {//what should i do here?}

JLayer is a decoder . By its very definition it does not know anything about volume, thats the job of the audio hardware that plays the sound.

Your problem stems from the fact that you are using the Player and defaul JavaSoundAudioDevice classes, which were meant as short, simple examples how to play an MP3, not as building blocks for a full fledged audio player.

You will have to copy or modify the source of JavaSoundAudioDevice (part of JLayer source) and hack it to support volume control. Et voila you can control volume.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM