Jump to content

Audio / Sound Snippet


Recommended Posts

Posted

About:

 

Definitely not the most efficient way nor the cleanest but if you are looking for a quick snippet to introduce audio into your scripts rapidly well here you go.

 

Example:

	public static void main(String args[]) {
		final Sound s = new Sound("C:/x/y/z/Korg-MS2000-DirtBass-C2.wav");
		s.play();
		try {
			Thread.sleep(5000);
		} catch (final InterruptedException e) {
			e.printStackTrace();
		}
		s.play();
	} 

Code:

public final class Sound {

	private final File soundFile;

	public Sound(final File soundFile) {
		this.soundFile = soundFile;
	}
	
	public Sound(final String soundFilePath) {
		this(new File(soundFilePath));
	}

	public final void play() {
		new PlayThread().start();
	}

	private class PlayThread extends Thread {
		
		byte buffer[] = new byte[10000];
		
		public void run() {
			try {
				
				final AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(soundFile);
				final AudioFormat audioFormat = audioInputStream.getFormat();
				final DataLine.Info dataLineInfo = new DataLine.Info(SourceDataLine.class, audioFormat);
				final SourceDataLine sourceDataLine = (SourceDataLine) AudioSystem.getLine(dataLineInfo);
				
				sourceDataLine.open(audioFormat);
				sourceDataLine.start();		
				
				int count;
				while ((count = audioInputStream.read(buffer, 0, buffer.length)) != -1) {
					if (count > 0) {
						sourceDataLine.write(buffer, 0, count);
					}
				}
				
				sourceDataLine.drain();
				sourceDataLine.close();
				
			} catch (final Exception e) {
				e.printStackTrace();
			}
		}
		
	}

}
  • Like 3
  • 4 months later...
Posted

How to use it?   For example, what a code, I can play


*野生JMod现身*
WUB WUB WUB

For example, what a code, I can play


*野生JMod现身*
WUB WUB WUB

If I want to make a sound, what code do I need?


*野生JMod现身*
WUB WUB WUB

 

what is the play method ?

what is the play method ?


 

关于:

 

绝对不是最有效的方法,也不是干净的,但如果你在这里寻找一个快速的片段音频引入脚本迅速以及你走。

 

例:

	公共静态无效的主要(字符串ARGS []){
		最后的声音S =新的声音(“C:/x/y/z/Korg-MS2000-DirtBass-C2.wav”);
		s.play();
		尝试{
			视频下载(5000);
		}赶上(最终InterruptedException的E){
			e.printStackTrace();
		}
		s.play();
	} 

码:

公共final类声音{

	私人最终文件音效档;

	市民声音(最终文件音效档){
		this.soundFile =音效档;
	}
	
	市民声音(最后弦乐soundFilePath){
		这(新文件(soundFilePath));
	}

	公众最终无效播放(){
		新PlayThread()开始();
	}

	私有类PlayThread继承Thread {
		
		字节的缓冲区[] =新的字节[10000]
		
		公共无效的run(){
			尝试{
				
				最终的AudioInputStream的AudioInputStream = AudioSystem.getAudioInputStream(音效档);
				最后AudioFormat的AudioFormat的= audioInputStream.getFormat();
				最后DataLine.Info dataLineInfo =新DataLine.Info(SourceDataLine.class,AudioFormat的);
				最终的SourceDataLine的SourceDataLine =(SourceDataLine的)AudioSystem.getLine(dataLineInfo);
				
				sourceDataLine.open(AudioFormat的);
				sourceDataLine.start();		
				
				诠释计数;
				而((计数= audioInputStream.read(缓冲液,0,buffer.length))!=  -  1){
					如果(计数> 0){
						sourceDataLine.write(缓冲,0,计数);
					}
				}
				
				sourceDataLine.drain();
				sourceDataLine.close();
				
			}赶上(最终例外五){
				e.printStackTrace();
			}
		}
		
	}

}

 

what is the play method ?

what is the play method ?

Posted

我甚至不知道你在说什么,什么bruh

  • private Sound s;

    int XX=1;

    if(XX==1){s.play(); sleep(random(1013, 1233));return State.WAIT;}

    After the implementation, stuck

public static void main(String args[]) {
final Sound s = new Sound("C:/1.wav");
s.play();
try {
Thread.sleep(5000);
} catch (final InterruptedException e) {
e.printStackTrace();
}
s.play();
 
 
 
 
 
  •  

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...