• MONEY за подписку! Ничего делать не надо совсем, всего-то подписаться на тг одмена и нажать кнопку "Принять участие" в розыгрыше: https://t.me/govthing/7650

Часть функционала MusicPlayer | exp 3.1

Начинающий
Начинающий
Статус
Оффлайн
Регистрация
15 Фев 2024
Сообщения
117
Реакции
0
Выберите загрузчик игры
  1. Прочие моды
Привет! мой второй код для югейма, музыка работает в 1 модуль а не в 2 в 3 как у других.
Пожалуйста, авторизуйтесь для просмотра ссылки.

Код:
Expand Collapse Copy
package im.expensive.functions.impl.misc;

import im.expensive.functions.api.Category;
import im.expensive.functions.api.Function;
import im.expensive.functions.api.FunctionRegister;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.util.text.StringTextComponent;

import javax.sound.sampled.*;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@FunctionRegister(name = "MusicPlayer", type = Category.Misc)
public class MusicPlayer extends Function {
    private final Minecraft mc = Minecraft.getInstance();
    private Clip clip;
    private List<File> musicFiles = new ArrayList<>();
    private int currentTrackIndex = -1;
    private float volume = 1.0f;

    public MusicPlayer() {
        super();
    }

    @Override
    public void onEnable() {
        super.onEnable();
        mc.displayGuiScreen(new MusicMenu());
    }

    @Override
    public void onDisable() {
        super.onDisable();
        stopMusic();
    }

    public void playMusic(File musicFile) {
        stopMusic();
        try {
            AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(musicFile);
            clip = AudioSystem.getClip();
            clip.open(audioInputStream);
            setVolume(volume);
            clip.start();
        } catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
            e.printStackTrace();
        }
    }

    public void stopMusic() {
        if (clip != null && clip.isRunning()) {
            clip.stop();
            clip.close();
        }
    }

    private void nextTrack() {
        if (!musicFiles.isEmpty()) {
            currentTrackIndex = (currentTrackIndex + 1) % musicFiles.size();
            playMusic(musicFiles.get(currentTrackIndex));
        }
    }

    private void previousTrack() {
        if (!musicFiles.isEmpty()) {
            currentTrackIndex = (currentTrackIndex - 1 + musicFiles.size()) % musicFiles.size();
            playMusic(musicFiles.get(currentTrackIndex));
        }
    }

    private void setVolume(float volume) {
        if (clip != null) {
            FloatControl volumeControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
            volumeControl.setValue(20f * (float) Math.log10(volume)); // Установить громкость
        }
    }

    private class MusicMenu extends Screen {
        protected MusicMenu() {
            super(new StringTextComponent("Music Player"));
        }

        @Override
        protected void init() {
            addButton(new Button(width / 2 - 100, height / 2 - 40, 200, 20,
                    new StringTextComponent("Слушать музыку"),
                    button -> {
                        File musicFile = new File("ваш путь к музыке.wav");
                        if (musicFile.exists()) {
                            musicFiles.add(musicFile);
                            if (currentTrackIndex == -1) {
                                currentTrackIndex = 0;
                                playMusic(musicFile);
                            } else {
                                nextTrack();
                            }
                        }
                    }
            ));

            addButton(new Button(width / 2 - 100, height / 2 - 10, 200, 20,
                    new StringTextComponent("Остановить музыку"),
                    button -> {
                        stopMusic();
                    }
            ));

            addButton(new Button(width / 2 - 100, height / 2 + 20, 90, 20,
                    new StringTextComponent("<< Назад"),
                    button -> {
                        previousTrack();
                    }
            ));

            addButton(new Button(width / 2 + 10, height / 2 + 20, 90, 20,
                    new StringTextComponent("Дальше >>"),
                    button -> {
                        nextTrack();
                    }
            ));


            addButton(new Button(width / 2 - 100, height / 2 + 60, 90, 20,
                    new StringTextComponent("-"),
                    button -> {
                        if (volume > 0.0f) {
                            volume = Math.max(0.0f, volume - 0.1f);
                            setVolume(volume);
                        }
                    }
            ));


            addButton(new Button(width / 2 + 10, height / 2 + 60, 90, 20,
                    new StringTextComponent("+"),
                    button -> {
                        if (volume < 1.0f) {
                            volume = Math.min(1.0f, volume + 0.1f);
                            setVolume(volume);
                        }
                    }
            ));
        }
    }
}
Все звуки добавляйте с расширением .wav
Можете добавить еще пару звуков чтобы переключать, я делал только с 1
УДАЧИ
 
Привет! мой второй код для югейма, музыка работает в 1 модуль а не в 2 в 3 как у других.
Пожалуйста, авторизуйтесь для просмотра ссылки.

Код:
Expand Collapse Copy
package im.expensive.functions.impl.misc;

import im.expensive.functions.api.Category;
import im.expensive.functions.api.Function;
import im.expensive.functions.api.FunctionRegister;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.util.text.StringTextComponent;

import javax.sound.sampled.*;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@FunctionRegister(name = "MusicPlayer", type = Category.Misc)
public class MusicPlayer extends Function {
    private final Minecraft mc = Minecraft.getInstance();
    private Clip clip;
    private List<File> musicFiles = new ArrayList<>();
    private int currentTrackIndex = -1;
    private float volume = 1.0f;

    public MusicPlayer() {
        super();
    }

    @Override
    public void onEnable() {
        super.onEnable();
        mc.displayGuiScreen(new MusicMenu());
    }

    @Override
    public void onDisable() {
        super.onDisable();
        stopMusic();
    }

    public void playMusic(File musicFile) {
        stopMusic();
        try {
            AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(musicFile);
            clip = AudioSystem.getClip();
            clip.open(audioInputStream);
            setVolume(volume);
            clip.start();
        } catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
            e.printStackTrace();
        }
    }

    public void stopMusic() {
        if (clip != null && clip.isRunning()) {
            clip.stop();
            clip.close();
        }
    }

    private void nextTrack() {
        if (!musicFiles.isEmpty()) {
            currentTrackIndex = (currentTrackIndex + 1) % musicFiles.size();
            playMusic(musicFiles.get(currentTrackIndex));
        }
    }

    private void previousTrack() {
        if (!musicFiles.isEmpty()) {
            currentTrackIndex = (currentTrackIndex - 1 + musicFiles.size()) % musicFiles.size();
            playMusic(musicFiles.get(currentTrackIndex));
        }
    }

    private void setVolume(float volume) {
        if (clip != null) {
            FloatControl volumeControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
            volumeControl.setValue(20f * (float) Math.log10(volume)); // Установить громкость
        }
    }

    private class MusicMenu extends Screen {
        protected MusicMenu() {
            super(new StringTextComponent("Music Player"));
        }

        @Override
        protected void init() {
            addButton(new Button(width / 2 - 100, height / 2 - 40, 200, 20,
                    new StringTextComponent("Слушать музыку"),
                    button -> {
                        File musicFile = new File("ваш путь к музыке.wav");
                        if (musicFile.exists()) {
                            musicFiles.add(musicFile);
                            if (currentTrackIndex == -1) {
                                currentTrackIndex = 0;
                                playMusic(musicFile);
                            } else {
                                nextTrack();
                            }
                        }
                    }
            ));

            addButton(new Button(width / 2 - 100, height / 2 - 10, 200, 20,
                    new StringTextComponent("Остановить музыку"),
                    button -> {
                        stopMusic();
                    }
            ));

            addButton(new Button(width / 2 - 100, height / 2 + 20, 90, 20,
                    new StringTextComponent("<< Назад"),
                    button -> {
                        previousTrack();
                    }
            ));

            addButton(new Button(width / 2 + 10, height / 2 + 20, 90, 20,
                    new StringTextComponent("Дальше >>"),
                    button -> {
                        nextTrack();
                    }
            ));


            addButton(new Button(width / 2 - 100, height / 2 + 60, 90, 20,
                    new StringTextComponent("-"),
                    button -> {
                        if (volume > 0.0f) {
                            volume = Math.max(0.0f, volume - 0.1f);
                            setVolume(volume);
                        }
                    }
            ));


            addButton(new Button(width / 2 + 10, height / 2 + 60, 90, 20,
                    new StringTextComponent("+"),
                    button -> {
                        if (volume < 1.0f) {
                            volume = Math.min(1.0f, volume + 0.1f);
                            setVolume(volume);
                        }
                    }
            ));
        }
    }
}
Все звуки добавляйте с расширением .wav
Можете добавить еще пару звуков чтобы переключать, я делал только с 1
УДАЧИ
типа C:\Desctop\тд ?
типа C:\Desctop\тд ?
а все
 
Последнее редактирование:
Привет! мой второй код для югейма, музыка работает в 1 модуль а не в 2 в 3 как у других.
Пожалуйста, авторизуйтесь для просмотра ссылки.

Код:
Expand Collapse Copy
package im.expensive.functions.impl.misc;

import im.expensive.functions.api.Category;
import im.expensive.functions.api.Function;
import im.expensive.functions.api.FunctionRegister;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.util.text.StringTextComponent;

import javax.sound.sampled.*;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@FunctionRegister(name = "MusicPlayer", type = Category.Misc)
public class MusicPlayer extends Function {
    private final Minecraft mc = Minecraft.getInstance();
    private Clip clip;
    private List<File> musicFiles = new ArrayList<>();
    private int currentTrackIndex = -1;
    private float volume = 1.0f;

    public MusicPlayer() {
        super();
    }

    @Override
    public void onEnable() {
        super.onEnable();
        mc.displayGuiScreen(new MusicMenu());
    }

    @Override
    public void onDisable() {
        super.onDisable();
        stopMusic();
    }

    public void playMusic(File musicFile) {
        stopMusic();
        try {
            AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(musicFile);
            clip = AudioSystem.getClip();
            clip.open(audioInputStream);
            setVolume(volume);
            clip.start();
        } catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
            e.printStackTrace();
        }
    }

    public void stopMusic() {
        if (clip != null && clip.isRunning()) {
            clip.stop();
            clip.close();
        }
    }

    private void nextTrack() {
        if (!musicFiles.isEmpty()) {
            currentTrackIndex = (currentTrackIndex + 1) % musicFiles.size();
            playMusic(musicFiles.get(currentTrackIndex));
        }
    }

    private void previousTrack() {
        if (!musicFiles.isEmpty()) {
            currentTrackIndex = (currentTrackIndex - 1 + musicFiles.size()) % musicFiles.size();
            playMusic(musicFiles.get(currentTrackIndex));
        }
    }

    private void setVolume(float volume) {
        if (clip != null) {
            FloatControl volumeControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
            volumeControl.setValue(20f * (float) Math.log10(volume)); // Установить громкость
        }
    }

    private class MusicMenu extends Screen {
        protected MusicMenu() {
            super(new StringTextComponent("Music Player"));
        }

        @Override
        protected void init() {
            addButton(new Button(width / 2 - 100, height / 2 - 40, 200, 20,
                    new StringTextComponent("Слушать музыку"),
                    button -> {
                        File musicFile = new File("ваш путь к музыке.wav");
                        if (musicFile.exists()) {
                            musicFiles.add(musicFile);
                            if (currentTrackIndex == -1) {
                                currentTrackIndex = 0;
                                playMusic(musicFile);
                            } else {
                                nextTrack();
                            }
                        }
                    }
            ));

            addButton(new Button(width / 2 - 100, height / 2 - 10, 200, 20,
                    new StringTextComponent("Остановить музыку"),
                    button -> {
                        stopMusic();
                    }
            ));

            addButton(new Button(width / 2 - 100, height / 2 + 20, 90, 20,
                    new StringTextComponent("<< Назад"),
                    button -> {
                        previousTrack();
                    }
            ));

            addButton(new Button(width / 2 + 10, height / 2 + 20, 90, 20,
                    new StringTextComponent("Дальше >>"),
                    button -> {
                        nextTrack();
                    }
            ));


            addButton(new Button(width / 2 - 100, height / 2 + 60, 90, 20,
                    new StringTextComponent("-"),
                    button -> {
                        if (volume > 0.0f) {
                            volume = Math.max(0.0f, volume - 0.1f);
                            setVolume(volume);
                        }
                    }
            ));


            addButton(new Button(width / 2 + 10, height / 2 + 60, 90, 20,
                    new StringTextComponent("+"),
                    button -> {
                        if (volume < 1.0f) {
                            volume = Math.min(1.0f, volume + 0.1f);
                            setVolume(volume);
                        }
                    }
            ));
        }
    }
}
Все звуки добавляйте с расширением .wav
Можете добавить еще пару звуков чтобы переключать, я делал только с 1
УДАЧИ
я давным давно сливал, там и то реализация лучше была
 
Привет! мой второй код для югейма, музыка работает в 1 модуль а не в 2 в 3 как у других.
Пожалуйста, авторизуйтесь для просмотра ссылки.

Код:
Expand Collapse Copy
package im.expensive.functions.impl.misc;

import im.expensive.functions.api.Category;
import im.expensive.functions.api.Function;
import im.expensive.functions.api.FunctionRegister;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.util.text.StringTextComponent;

import javax.sound.sampled.*;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@FunctionRegister(name = "MusicPlayer", type = Category.Misc)
public class MusicPlayer extends Function {
    private final Minecraft mc = Minecraft.getInstance();
    private Clip clip;
    private List<File> musicFiles = new ArrayList<>();
    private int currentTrackIndex = -1;
    private float volume = 1.0f;

    public MusicPlayer() {
        super();
    }

    @Override
    public void onEnable() {
        super.onEnable();
        mc.displayGuiScreen(new MusicMenu());
    }

    @Override
    public void onDisable() {
        super.onDisable();
        stopMusic();
    }

    public void playMusic(File musicFile) {
        stopMusic();
        try {
            AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(musicFile);
            clip = AudioSystem.getClip();
            clip.open(audioInputStream);
            setVolume(volume);
            clip.start();
        } catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
            e.printStackTrace();
        }
    }

    public void stopMusic() {
        if (clip != null && clip.isRunning()) {
            clip.stop();
            clip.close();
        }
    }

    private void nextTrack() {
        if (!musicFiles.isEmpty()) {
            currentTrackIndex = (currentTrackIndex + 1) % musicFiles.size();
            playMusic(musicFiles.get(currentTrackIndex));
        }
    }

    private void previousTrack() {
        if (!musicFiles.isEmpty()) {
            currentTrackIndex = (currentTrackIndex - 1 + musicFiles.size()) % musicFiles.size();
            playMusic(musicFiles.get(currentTrackIndex));
        }
    }

    private void setVolume(float volume) {
        if (clip != null) {
            FloatControl volumeControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
            volumeControl.setValue(20f * (float) Math.log10(volume)); // Установить громкость
        }
    }

    private class MusicMenu extends Screen {
        protected MusicMenu() {
            super(new StringTextComponent("Music Player"));
        }

        @Override
        protected void init() {
            addButton(new Button(width / 2 - 100, height / 2 - 40, 200, 20,
                    new StringTextComponent("Слушать музыку"),
                    button -> {
                        File musicFile = new File("ваш путь к музыке.wav");
                        if (musicFile.exists()) {
                            musicFiles.add(musicFile);
                            if (currentTrackIndex == -1) {
                                currentTrackIndex = 0;
                                playMusic(musicFile);
                            } else {
                                nextTrack();
                            }
                        }
                    }
            ));

            addButton(new Button(width / 2 - 100, height / 2 - 10, 200, 20,
                    new StringTextComponent("Остановить музыку"),
                    button -> {
                        stopMusic();
                    }
            ));

            addButton(new Button(width / 2 - 100, height / 2 + 20, 90, 20,
                    new StringTextComponent("<< Назад"),
                    button -> {
                        previousTrack();
                    }
            ));

            addButton(new Button(width / 2 + 10, height / 2 + 20, 90, 20,
                    new StringTextComponent("Дальше >>"),
                    button -> {
                        nextTrack();
                    }
            ));


            addButton(new Button(width / 2 - 100, height / 2 + 60, 90, 20,
                    new StringTextComponent("-"),
                    button -> {
                        if (volume > 0.0f) {
                            volume = Math.max(0.0f, volume - 0.1f);
                            setVolume(volume);
                        }
                    }
            ));


            addButton(new Button(width / 2 + 10, height / 2 + 60, 90, 20,
                    new StringTextComponent("+"),
                    button -> {
                        if (volume < 1.0f) {
                            volume = Math.min(1.0f, volume + 0.1f);
                            setVolume(volume);
                        }
                    }
            ));
        }
    }
}
Все звуки добавляйте с расширением .wav
Можете добавить еще пару звуков чтобы переключать, я делал только с 1
УДАЧИ
честно у мойтена получше было, тем более у тебя как раз 2 модуля (класса) и используется, ты просто один вложил в функцию
 
Привет! мой второй код для югейма, музыка работает в 1 модуль а не в 2 в 3 как у других.
Пожалуйста, авторизуйтесь для просмотра ссылки.

Код:
Expand Collapse Copy
package im.expensive.functions.impl.misc;

import im.expensive.functions.api.Category;
import im.expensive.functions.api.Function;
import im.expensive.functions.api.FunctionRegister;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.util.text.StringTextComponent;

import javax.sound.sampled.*;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@FunctionRegister(name = "MusicPlayer", type = Category.Misc)
public class MusicPlayer extends Function {
    private final Minecraft mc = Minecraft.getInstance();
    private Clip clip;
    private List<File> musicFiles = new ArrayList<>();
    private int currentTrackIndex = -1;
    private float volume = 1.0f;

    public MusicPlayer() {
        super();
    }

    @Override
    public void onEnable() {
        super.onEnable();
        mc.displayGuiScreen(new MusicMenu());
    }

    @Override
    public void onDisable() {
        super.onDisable();
        stopMusic();
    }

    public void playMusic(File musicFile) {
        stopMusic();
        try {
            AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(musicFile);
            clip = AudioSystem.getClip();
            clip.open(audioInputStream);
            setVolume(volume);
            clip.start();
        } catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
            e.printStackTrace();
        }
    }

    public void stopMusic() {
        if (clip != null && clip.isRunning()) {
            clip.stop();
            clip.close();
        }
    }

    private void nextTrack() {
        if (!musicFiles.isEmpty()) {
            currentTrackIndex = (currentTrackIndex + 1) % musicFiles.size();
            playMusic(musicFiles.get(currentTrackIndex));
        }
    }

    private void previousTrack() {
        if (!musicFiles.isEmpty()) {
            currentTrackIndex = (currentTrackIndex - 1 + musicFiles.size()) % musicFiles.size();
            playMusic(musicFiles.get(currentTrackIndex));
        }
    }

    private void setVolume(float volume) {
        if (clip != null) {
            FloatControl volumeControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
            volumeControl.setValue(20f * (float) Math.log10(volume)); // Установить громкость
        }
    }

    private class MusicMenu extends Screen {
        protected MusicMenu() {
            super(new StringTextComponent("Music Player"));
        }

        @Override
        protected void init() {
            addButton(new Button(width / 2 - 100, height / 2 - 40, 200, 20,
                    new StringTextComponent("Слушать музыку"),
                    button -> {
                        File musicFile = new File("ваш путь к музыке.wav");
                        if (musicFile.exists()) {
                            musicFiles.add(musicFile);
                            if (currentTrackIndex == -1) {
                                currentTrackIndex = 0;
                                playMusic(musicFile);
                            } else {
                                nextTrack();
                            }
                        }
                    }
            ));

            addButton(new Button(width / 2 - 100, height / 2 - 10, 200, 20,
                    new StringTextComponent("Остановить музыку"),
                    button -> {
                        stopMusic();
                    }
            ));

            addButton(new Button(width / 2 - 100, height / 2 + 20, 90, 20,
                    new StringTextComponent("<< Назад"),
                    button -> {
                        previousTrack();
                    }
            ));

            addButton(new Button(width / 2 + 10, height / 2 + 20, 90, 20,
                    new StringTextComponent("Дальше >>"),
                    button -> {
                        nextTrack();
                    }
            ));


            addButton(new Button(width / 2 - 100, height / 2 + 60, 90, 20,
                    new StringTextComponent("-"),
                    button -> {
                        if (volume > 0.0f) {
                            volume = Math.max(0.0f, volume - 0.1f);
                            setVolume(volume);
                        }
                    }
            ));


            addButton(new Button(width / 2 + 10, height / 2 + 60, 90, 20,
                    new StringTextComponent("+"),
                    button -> {
                        if (volume < 1.0f) {
                            volume = Math.min(1.0f, volume + 0.1f);
                            setVolume(volume);
                        }
                    }
            ));
        }
    }
}
Все звуки добавляйте с расширением .wav
Можете добавить еще пару звуков чтобы переключать, я делал только с 1
УДАЧИ
а смысл нужно путь напрямую и даже название wav писать
 
а смысл нужно путь напрямую и даже название wav писать
.wav это расширение, напрямую как и везде типо target.png или же logo.png
я давным давно сливал, там и то реализация лучше была
Вот не давно увидел твою работу, реально классная. Но я всё впихнул в 1 модуль
 
А что у тебя за музыка в видео?
 
а куда надо закидывать музыку ну по какому пути я немного не пойму
 
мб сделать чтобы можно было загружать треки прям в игре?
 
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
ь
Привет! мой второй код для югейма, музыка работает в 1 модуль а не в 2 в 3 как у других.
Пожалуйста, авторизуйтесь для просмотра ссылки.

Код:
Expand Collapse Copy
package im.expensive.functions.impl.misc;

import im.expensive.functions.api.Category;
import im.expensive.functions.api.Function;
import im.expensive.functions.api.FunctionRegister;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.util.text.StringTextComponent;

import javax.sound.sampled.*;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@FunctionRegister(name = "MusicPlayer", type = Category.Misc)
public class MusicPlayer extends Function {
    private final Minecraft mc = Minecraft.getInstance();
    private Clip clip;
    private List<File> musicFiles = new ArrayList<>();
    private int currentTrackIndex = -1;
    private float volume = 1.0f;

    public MusicPlayer() {
        super();
    }

    @Override
    public void onEnable() {
        super.onEnable();
        mc.displayGuiScreen(new MusicMenu());
    }

    @Override
    public void onDisable() {
        super.onDisable();
        stopMusic();
    }

    public void playMusic(File musicFile) {
        stopMusic();
        try {
            AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(musicFile);
            clip = AudioSystem.getClip();
            clip.open(audioInputStream);
            setVolume(volume);
            clip.start();
        } catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
            e.printStackTrace();
        }
    }

    public void stopMusic() {
        if (clip != null && clip.isRunning()) {
            clip.stop();
            clip.close();
        }
    }

    private void nextTrack() {
        if (!musicFiles.isEmpty()) {
            currentTrackIndex = (currentTrackIndex + 1) % musicFiles.size();
            playMusic(musicFiles.get(currentTrackIndex));
        }
    }

    private void previousTrack() {
        if (!musicFiles.isEmpty()) {
            currentTrackIndex = (currentTrackIndex - 1 + musicFiles.size()) % musicFiles.size();
            playMusic(musicFiles.get(currentTrackIndex));
        }
    }

    private void setVolume(float volume) {
        if (clip != null) {
            FloatControl volumeControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
            volumeControl.setValue(20f * (float) Math.log10(volume)); // Установить громкость
        }
    }

    private class MusicMenu extends Screen {
        protected MusicMenu() {
            super(new StringTextComponent("Music Player"));
        }

        @Override
        protected void init() {
            addButton(new Button(width / 2 - 100, height / 2 - 40, 200, 20,
                    new StringTextComponent("Слушать музыку"),
                    button -> {
                        File musicFile = new File("ваш путь к музыке.wav");
                        if (musicFile.exists()) {
                            musicFiles.add(musicFile);
                            if (currentTrackIndex == -1) {
                                currentTrackIndex = 0;
                                playMusic(musicFile);
                            } else {
                                nextTrack();
                            }
                        }
                    }
            ));

            addButton(new Button(width / 2 - 100, height / 2 - 10, 200, 20,
                    new StringTextComponent("Остановить музыку"),
                    button -> {
                        stopMusic();
                    }
            ));

            addButton(new Button(width / 2 - 100, height / 2 + 20, 90, 20,
                    new StringTextComponent("<< Назад"),
                    button -> {
                        previousTrack();
                    }
            ));

            addButton(new Button(width / 2 + 10, height / 2 + 20, 90, 20,
                    new StringTextComponent("Дальше >>"),
                    button -> {
                        nextTrack();
                    }
            ));


            addButton(new Button(width / 2 - 100, height / 2 + 60, 90, 20,
                    new StringTextComponent("-"),
                    button -> {
                        if (volume > 0.0f) {
                            volume = Math.max(0.0f, volume - 0.1f);
                            setVolume(volume);
                        }
                    }
            ));


            addButton(new Button(width / 2 + 10, height / 2 + 60, 90, 20,
                    new StringTextComponent("+"),
                    button -> {
                        if (volume < 1.0f) {
                            volume = Math.min(1.0f, volume + 0.1f);
                            setVolume(volume);
                        }
                    }
            ));
        }
    }
}
Все звуки добавляйте с расширением .wav
Можете добавить еще пару звуков чтобы переключать, я делал только с 1
УДАЧИ

mc.dataDir для слабых или что? xD
 
улучшите, мне лень
 
а куда музыку кидать
 
Назад
Сверху Снизу