简体   繁体   English

使用jlayer更改音量java?

[英]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. 我有一个Java主类和一个Java JFrame。 I wanna add jslider to change volume in my mp3 player. 我想添加jslider来改变我的mp3播放器中的音量。 What should i do? 我该怎么办?

my_player2_func my_player2_func

class my_player2_func{ static Player player; class my_player2_func {静态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 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 . JLayer是解码器 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. 您的问题源于您正在使用Player和defaul JavaSoundAudioDevice类的事实,这些类作为播放MP3的简短示例,而不是作为完整的音频播放器的基础。

You will have to copy or modify the source of JavaSoundAudioDevice (part of JLayer source) and hack it to support volume control. 您将必须复制或修改JavaSoundAudioDevice的源代码(JLayer源代码的一部分),并对其进行破解以支持音量控制。 Et voila you can control volume. 等等,您可以控制音量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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