简体   繁体   中英

Add audio to an MP4 in Java (JDK) without FFmpeg

using this code you can add .wav and other supported formats by jdk to your java code

import java.io.File;
import javax.sound.sampled.*;

use try catch or throws method here i used try catch method

public class Music {
    public static void main(String[] args){

        try{
            File file = new File("--file location--");
            AudioInputStream audioStream =AudioSystem.getAudioInputStream(file);
            Clip clip = AudioSystem.getClip();
            clip.open(audioStream);

            clip.start();

            Thread.sleep(s*1000); // s = time in seconds

        }catch(Exception e){
            System.out.println(e);
            System.out.println("File Not Supported");
         }

    }
}

Click here to open my github repository AddingAudioToJava

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