mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-26 19:45:36 +00:00
Separated FFDec core library and the rest (GUI).
FFDec Library is now LGPLv3, others stay GPLv3. Version changed to 3.0.0 for FFDec, 1.0.0 for FFDec Library.
This commit is contained in:
103
libsrc/ffdec_lib/src/com/jpexs/helpers/SoundPlayer.java
Normal file
103
libsrc/ffdec_lib/src/com/jpexs/helpers/SoundPlayer.java
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2014 JPEXS, All rights reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.helpers;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
import javax.sound.sampled.Clip;
|
||||
import javax.sound.sampled.Line;
|
||||
import javax.sound.sampled.LineEvent;
|
||||
import javax.sound.sampled.LineListener;
|
||||
import javax.sound.sampled.LineUnavailableException;
|
||||
import javax.sound.sampled.UnsupportedAudioFileException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class SoundPlayer {
|
||||
|
||||
private final Clip clip;
|
||||
|
||||
public SoundPlayer(InputStream is) throws LineUnavailableException, IOException, UnsupportedAudioFileException {
|
||||
clip = (Clip) AudioSystem.getLine(new Line.Info(Clip.class));
|
||||
clip.open(AudioSystem.getAudioInputStream(new BufferedInputStream(is)));
|
||||
}
|
||||
|
||||
public long samplesCount() {
|
||||
return clip.getMicrosecondLength();
|
||||
}
|
||||
|
||||
public void play() {
|
||||
|
||||
final SoundPlayer t = this;
|
||||
clip.addLineListener(new LineListener() {
|
||||
|
||||
@Override
|
||||
public void update(LineEvent event) {
|
||||
if (event.getType() == LineEvent.Type.STOP) {
|
||||
//clip.close();
|
||||
|
||||
synchronized (t) {
|
||||
t.notifyAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
clip.start();
|
||||
try {
|
||||
synchronized (this) {
|
||||
wait();
|
||||
}
|
||||
} catch (InterruptedException ex) {
|
||||
//Ignore
|
||||
}
|
||||
}
|
||||
|
||||
public long getSamplePosition() {
|
||||
return clip.getMicrosecondPosition();
|
||||
}
|
||||
|
||||
public void setPosition(long frames) {
|
||||
clip.setMicrosecondPosition(frames);
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
clip.stop();
|
||||
}
|
||||
|
||||
public boolean isPlaying() {
|
||||
return clip.isActive();
|
||||
}
|
||||
|
||||
public long getFrameRate() {
|
||||
return 1000000L;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
try {
|
||||
if (clip != null) {
|
||||
clip.close();
|
||||
}
|
||||
} finally {
|
||||
super.finalize();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user