本文整理汇总了Java中javazoom.jl.player.AudioDevice类的典型用法代码示例。如果您正苦于以下问题:Java AudioDevice类的具体用法?Java AudioDevice怎么用?Java AudioDevice使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AudioDevice类属于javazoom.jl.player包,在下文中一共展示了AudioDevice类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: close
import javazoom.jl.player.AudioDevice; //导入依赖的package包/类
/**
* Cloases this player. Any audio currently playing is stopped
* immediately.
*/
public synchronized void close()
{
AudioDevice out = audio;
if (out != null)
{
closed = true;
audio = null;
// this may fail, so ensure object state is set up before
// calling this method.
out.close();
lastPosition = out.getPosition();
try
{
bitstream.close();
}
catch (BitstreamException ex)
{}
}
}
示例2: close
import javazoom.jl.player.AudioDevice; //导入依赖的package包/类
/**
* Closes this player. Any audio currently playing is stopped immediately.
*/
public synchronized void close() {
AudioDevice out = audio;
if (out != null) {
closed = true;
audio = null;
// this may fail, so ensure object state is set up before
// calling this method.
out.close();
lastPosition = out.getPosition();
try {
bitstream.close();
} catch (BitstreamException ex) {
}
}
}
示例3: close
import javazoom.jl.player.AudioDevice; //导入依赖的package包/类
/**
* Cloases this player. Any audio currently playing is stopped
* immediately.
*/
public synchronized void close() {
AudioDevice out = audio;
if (out != null) {
closed = true;
audio = null;
// this may fail, so ensure object state is set up before
// calling this method.
out.close();
lastPosition = out.getPosition();
try {
bitstream.close();
} catch (BitstreamException ex) {
}
}
}
示例4: AdvancedPlayer
import javazoom.jl.player.AudioDevice; //导入依赖的package包/类
public AdvancedPlayer(InputStream stream, AudioDevice device) throws JavaLayerException
{
bitstream = new Bitstream(stream);
if (device!=null) audio = device;
else audio = FactoryRegistry.systemRegistry().createAudioDevice();
audio.open(decoder = new Decoder());
}
示例5: play
import javazoom.jl.player.AudioDevice; //导入依赖的package包/类
/**
* Plays a number of MPEG audio frames.
*
* @param frames The number of frames to play.
* @return true if the last frame was played, or false if there are
* more frames.
*/
public boolean play(int frames) throws JavaLayerException
{
boolean ret = true;
// report to listener
if(listener != null) listener.playbackStarted(createEvent(PlaybackEvent.STARTED));
while (frames-- > 0 && ret)
{
ret = decodeFrame();
}
// if (!ret)
{
// last frame, ensure all data flushed to the audio device.
AudioDevice out = audio;
if (out != null)
{
// System.out.println(audio.getPosition());
out.flush();
// System.out.println(audio.getPosition());
synchronized (this)
{
complete = (!closed);
close();
}
// report to listener
if(listener != null) listener.playbackFinished(createEvent(out, PlaybackEvent.STOPPED));
}
}
return ret;
}
示例6: decodeFrame
import javazoom.jl.player.AudioDevice; //导入依赖的package包/类
/**
* Decodes a single frame.
*
* @return true if there are no more frames to decode, false otherwise.
*/
protected boolean decodeFrame() throws JavaLayerException
{
try
{
AudioDevice out = audio;
if (out == null) return false;
Header h = bitstream.readFrame();
if (h == null) return false;
// sample buffer set when decoder constructed
SampleBuffer output = (SampleBuffer) decoder.decodeFrame(h, bitstream);
synchronized (this)
{
out = audio;
if(out != null)
{
out.write(output.getBuffer(), 0, output.getBufferLength());
}
}
bitstream.closeFrame();
}
catch (RuntimeException ex)
{
throw new JavaLayerException("Exception decoding audio frame", ex);
}
return true;
}
示例7: playClip
import javazoom.jl.player.AudioDevice; //导入依赖的package包/类
private void playClip(final String clipName, final PlayerID playerId) {
if (beSilent || isMuted(clipName)) {
return;
}
// run in a new thread, so that we do not delay the game
String folder = clipName;
if (playerId != null) {
folder += "_" + playerId.getName();
}
final URI clip = loadClip(folder).orElse(loadClip(clipName).orElse(null));
// clip may still be null, we try to load all phases/all sound, for example: clipName = "phase_technology", folder =
// "phase_technology_Japanese"
if (clip != null) {
new Thread(() -> {
try {
final Optional<InputStream> inputStream = UrlStreams.openStream(clip.toURL());
if (inputStream.isPresent()) {
final AudioDevice audioDevice = FactoryRegistry.systemRegistry().createAudioDevice();
new AdvancedPlayer(inputStream.get(), audioDevice).play();
}
} catch (final Exception e) {
ClientLogger.logError("Failed to play: " + clip, e);
}
}).start();
}
}
示例8: AdvancedPlayer
import javazoom.jl.player.AudioDevice; //导入依赖的package包/类
public AdvancedPlayer(InputStream stream, AudioDevice device) throws JavaLayerException {
bitstream = new Bitstream(stream);
if (device != null)
audio = device;
else
audio = FactoryRegistry.systemRegistry().createAudioDevice();
audio.open(decoder = new Decoder());
}
示例9: play
import javazoom.jl.player.AudioDevice; //导入依赖的package包/类
/**
* Plays a number of MPEG audio frames.
*
* @param frames
* The number of frames to play.
* @return true if the last frame was played, or false if there are more
* frames.
*/
public boolean play(int frames) throws JavaLayerException {
boolean ret = true;
// report to listener
if (listener != null)
listener.playbackStarted(createEvent(PlaybackEvent.STARTED));
while (frames-- > 0 && ret) {
ret = decodeFrame();
currentPosition++;
if (positionListener != null) {
positionListener.onNewPosition(currentPosition);
}
}
// if (!ret)
{
// last frame, ensure all data flushed to the audio device.
AudioDevice out = audio;
if (out != null) {
// System.out.println(audio.getPosition());
out.flush();
// System.out.println(audio.getPosition());
synchronized (this) {
complete = (!closed);
close();
}
// report to listener
if (listener != null)
listener.playbackCompleted(createEvent(out, PlaybackEvent.STOPPED));
}
}
return ret;
}
示例10: decodeFrame
import javazoom.jl.player.AudioDevice; //导入依赖的package包/类
/**
* Decodes a single frame.
*
* @return true if there are no more frames to decode, false otherwise.
*/
protected boolean decodeFrame() throws JavaLayerException {
try {
AudioDevice out = audio;
if (out == null)
return false;
Header h = bitstream.readFrame();
if (h == null)
return false;
// sample buffer set when decoder constructed
SampleBuffer output = (SampleBuffer) decoder.decodeFrame(h, bitstream);
synchronized (this) {
out = audio;
if (out != null) {
out.write(output.getBuffer(), 0, output.getBufferLength());
}
}
bitstream.closeFrame();
} catch (RuntimeException ex) {
throw new JavaLayerException("Exception decoding audio frame", ex);
}
return true;
}
示例11: AdvancedPlayer
import javazoom.jl.player.AudioDevice; //导入依赖的package包/类
public AdvancedPlayer(InputStream stream, AudioDevice device) throws JavaLayerException {
bitstream = new Bitstream(stream);
if (device != null) {
audio = device;
} else {
audio = FactoryRegistry.systemRegistry().createAudioDevice();
}
audio.open(decoder = new Decoder());
}
示例12: play
import javazoom.jl.player.AudioDevice; //导入依赖的package包/类
/**
* Plays a number of MPEG audio frames.
*
* @param frames The number of frames to play.
* @return true if the last frame was played, or false if there are
* more frames.
*/
public boolean play(int frames) throws JavaLayerException {
boolean ret = true;
boolean firstTime = true;
while (frames-- > 0 && ret) {
ret = decodeFrame();
if(firstTime) {
// report to listener
if (listener != null) {
listener.playbackStarted(createEvent(PlaybackEvent.STARTED));
}
firstTime = false;
}
}
// if (!ret)
{
// last frame, ensure all data flushed to the audio device.
AudioDevice out = audio;
if (out != null) {
// System.out.println(audio.getPosition());
out.flush();
// System.out.println(audio.getPosition());
synchronized (this) {
complete = (!closed);
close();
}
// report to listener
if (listener != null) {
listener.playbackFinished(createEvent(out, PlaybackEvent.STOPPED));
}
}
}
return ret;
}