本文整理汇总了Java中com.xuggle.xuggler.IAudioSamples.findSampleBitDepth方法的典型用法代码示例。如果您正苦于以下问题:Java IAudioSamples.findSampleBitDepth方法的具体用法?Java IAudioSamples.findSampleBitDepth怎么用?Java IAudioSamples.findSampleBitDepth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.xuggle.xuggler.IAudioSamples
的用法示例。
在下文中一共展示了IAudioSamples.findSampleBitDepth方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: openJavaSound
import com.xuggle.xuggler.IAudioSamples; //导入方法依赖的package包/类
private static void openJavaSound(IStreamCoder aAudioCoder) {
AudioFormat audioFormat = new AudioFormat(aAudioCoder.getSampleRate(),
(int)IAudioSamples.findSampleBitDepth(aAudioCoder.getSampleFormat()),
aAudioCoder.getChannels(),
true, /* xuggler defaults to signed 16 bit samples */
false);
DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat);
try
{
mLine = (SourceDataLine) AudioSystem.getLine(info);
/**
* if that succeeded, try opening the line.
*/
mLine.open(audioFormat);
/**
* And if that succeed, start the line.
*/
mLine.start();
}
catch (LineUnavailableException e)
{
throw new RuntimeException("could not open audio line");
}
}
示例2: open
import com.xuggle.xuggler.IAudioSamples; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
private void open(URLVideoSource src) throws IOException {
try {
if("file".equals(src.getURL().getProtocol())) {
File f = new File(src.getURL().toURI());
if (container.open(f.getAbsolutePath(), IContainer.Type.READ, null) < 0)
throw new IOException("could not open " + f.getAbsolutePath());
} else {
String urlStr = TextUtilities.toString(src.getURL());
if (container.open(urlStr, IContainer.Type.READ, null) < 0)
throw new IOException("could not open " + urlStr);
}
} catch(URISyntaxException e) {
throw new IOException(e);
}
// query how many streams the call to open found
int numStreams = container.getNumStreams();
// and iterate through the streams to find the first audio stream
int videoStreamId = -1;
int audioStreamId = -1;
for(int i = 0; i < numStreams; i++) {
// Find the stream object
IStream stream = container.getStream(i);
// Get the pre-configured decoder that can decode this stream;
IStreamCoder coder = stream.getStreamCoder();
if (videoStreamId == -1 && coder.getCodecType() == ICodec.Type.CODEC_TYPE_VIDEO) {
videoStreamId = i;
videoStream = stream;
videoCoder = coder;
}
else if (audioStreamId == -1 && coder.getCodecType() == ICodec.Type.CODEC_TYPE_AUDIO) {
audioStreamId = i;
audioStream = stream;
audioCoder = coder;
audioFormat = new AudioFormat(
audioCoder.getSampleRate(),
(int)IAudioSamples.findSampleBitDepth(audioCoder.getSampleFormat()),
audioCoder.getChannels(),
true, /* xuggler defaults to signed 16 bit samples */
false);
}
}
if (videoStreamId == -1 && audioStreamId == -1)
throw new IOException("could not find audio or video stream in container in " + src);
/*
* Check if we have a video stream in this file. If so let's open up our decoder so it can
* do work.
*/
if (videoCoder != null) {
if(videoCoder.open() < 0)
throw new IOException("could not open audio decoder for container " + src);
if (videoCoder.getPixelType() != IPixelFormat.Type.RGB24) {
resampler = IVideoResampler.make(
videoCoder.getWidth(), videoCoder.getHeight(),
IPixelFormat.Type.RGB24,
videoCoder.getWidth(), videoCoder.getHeight(),
videoCoder.getPixelType());
if (resampler == null)
throw new IOException("could not create color space resampler for " + src);
}
}
if (audioCoder != null) {
if (audioCoder.open() < 0)
throw new IOException("could not open audio decoder for container: " + src);
}
decoderThread = new Thread(this, src.getURL().toString());
decoderThread.setPriority(Thread.MIN_PRIORITY);
decoderThread.setDaemon(true);
doDecode.set(true);
decoderThread.start();
}
示例3: initialize
import com.xuggle.xuggler.IAudioSamples; //导入方法依赖的package包/类
/**
* Initializes this audio player thread with the given audio coder information.
* <p>
* Returns an integer representing any conversions that must be performed on the audio data.
* @param audioCoder the audio coder
* @return int
*/
public int initialize(IStreamCoder audioCoder) {
if (this.line != null) {
this.line.close();
this.line = null;
}
// make sure the given audio coder is not null
// this can happen with videos that are just video
if (audioCoder != null) {
int result = XugglerAudioData.CONVERSION_NONE;
int sampleRate = audioCoder.getSampleRate();
int bitDepth = (int)IAudioSamples.findSampleBitDepth(audioCoder.getSampleFormat());
int channels = audioCoder.getChannels();
// attempt to use the media's audio format
AudioFormat format = new AudioFormat(sampleRate, bitDepth, channels, true, false);
DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
// see if its supported
if (!AudioSystem.isLineSupported(info)) {
// if its not supported, this is typically due to the number of playback channels
// lets try the same format with just 2 channels (stereo)
if (channels > 2) {
format = new AudioFormat(sampleRate, bitDepth, 2, true, false);
info = new DataLine.Info(SourceDataLine.class, format);
// check if its supported
if (AudioSystem.isLineSupported(info)) {
// flag that downmixing must take place
result |= XugglerAudioData.CONVERSION_TO_STEREO;
}
}
// if its still not supported check the bit depth
if (!AudioSystem.isLineSupported(info)) {
// otherwise it could be due to the bit depth
// use either the audio format or the down mixed format
AudioFormat source = format;
// try to see if converting it to 16 bit will work
AudioFormat target = new AudioFormat(sampleRate, 16, format.getChannels(), true, false);
if (AudioSystem.isConversionSupported(target, source)) {
// setup the line
info = new DataLine.Info(SourceDataLine.class, target);
format = target;
// flag that a bit depth conversion must take place
result |= XugglerAudioData.CONVERSION_TO_BIT_DEPTH_16;
} else {
// if we still can't get it to be supported just give up and log a message
LOGGER.warn("The audio format is not supported by JavaSound and could not be converted: " + format);
this.line = null;
return -1;
}
}
}
try {
// create and open JavaSound
this.line = (SourceDataLine)AudioSystem.getLine(info);
this.line.open(format);
this.line.start();
return result;
} catch (LineUnavailableException e) {
// if a line isn't available then just dont play any sound
// and just continue normally
LOGGER.error("Line not available for audio playback: ", e);
this.line = null;
return -1;
}
}
return -1;
}