- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是具有症状的代码:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.zove.xuggleraudio;
import com.xuggle.xuggler.IAudioSamples;
import com.xuggle.xuggler.IContainer;
import com.xuggle.xuggler.IStream;
import com.xuggle.xuggler.IStreamCoder;
import com.xuggle.xuggler.ICodec;
import com.xuggle.xuggler.IPacket;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.Line;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.SourceDataLine;
/**
* Class that represents an audio player with the expected
* controls (start, stop, pause, resume).
* @author Mciavilli
*/
public class Audio
{
//The name of the file to be played
private final String filename;
//Our connection to the mixer
private final SourceDataLine mLine;
//The index of the audio stream inside the file
private final int audioId;
//Xuggler media container
private final IContainer container;
//The stream decoder
private final IStreamCoder streamCoder;
/*
* Constructor that takes a String argument
*/
public Audio(String filename)
{
this.filename = filename;
//Create Xuggler container object
this.container = IContainer.make();
//Open the container
if(container.open(filename, IContainer.Type.READ, null) < 0)
throw new IllegalArgumentException("Invalid file name: " + this.filename);
//find the audio stream within contained streams
this.audioId = getAudioId(container);
//get the audio stream
IStream stream = container.getStream(audioId);
//get the stream decoder
this.streamCoder = stream.getStreamCoder();
//open the stream decoder
if (this.streamCoder.open() < 0)
throw new RuntimeException("could not open audio decoder for container: "
+ filename);
//Get a pipe to the sound mixer
this.mLine = readySoundSystem(streamCoder);
}
private int getAudioId(IContainer container)
{
//see how many streams are there
int numStreams = container.getNumStreams();
int audioId = -1;
for(int i = 0; i < numStreams ; i++)
{
IStream stream = container.getStream(i);
IStreamCoder streamCoder = stream.getStreamCoder();
if(streamCoder.getCodecType() == ICodec.Type.CODEC_TYPE_AUDIO)
audioId = i;
break;
}//end for statement
//No audio stream found
if(audioId == -1)
throw new RuntimeException("Failed to find an audio stream in:" +
this.filename);
return audioId;
}//end method getAudioId
private SourceDataLine readySoundSystem(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
{
SourceDataLine 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");
}
return mLine;
}//end method readySoundSystem
/*
* starts playing the file.
* returns true if successful.
* should be called only once per Audio object
*/
public boolean start()
{
if(!mLine.isActive())
{
IPacket packet = IPacket.make();
while(container.readNextPacket(packet) >= 0)
{
/*
* Now we have a packet, let's see if it belongs to our audio stream
*/
if (packet.getStreamIndex() == this.audioId)
{
/*
* We allocate a set of samples with the same number of channels as the
* coder tells us is in this buffer.
*
* We also pass in a buffer size (1024 in our example), although Xuggler
* will probably allocate more space than just the 1024 (it's not important why).
*/
IAudioSamples samples = IAudioSamples.make(1024, this.streamCoder.getChannels());
/*
* A packet can actually contain multiple sets of samples (or frames of samples
* in audio-decoding speak). So, we may need to call decode audio multiple
* times at different offsets in the packet's data. We capture that here.
*/
int offset = 0;
/*
* Keep going until we've processed all data
*/
while(offset < packet.getSize())
{
int bytesDecoded = this.streamCoder.decodeAudio(samples, packet, offset);
if (bytesDecoded < 0)
throw new RuntimeException("got error decoding audio in: " + filename);
offset += bytesDecoded;
/*
* Some decoder will consume data in a packet, but will not be able to construct
* a full set of samples yet. Therefore you should always check if you
* got a complete set of samples from the decoder
*/
if (samples.isComplete())
{
playSound(samples);
}
}//end inner while block
}//end inner if block
else
{
/*
* This packet isn't part of our audio stream, so we just silently drop it.
*/
do {} while(false);
}//end else block
}//end outer while block
//success!
return true;
}//end outer if block
//The sound is already playing
return false;
}//end method start
private void playSound(IAudioSamples aSamples)
{
/**
* We're just going to dump all the samples into the line.
*/
byte[] rawBytes = aSamples.getData().getByteArray(0, aSamples.getSize());
this.mLine.write(rawBytes, 0, aSamples.getSize());
}//end method playJavaSound
/*
* stops the playback
* returns true if suucessful
*/
public boolean stop()
{
if(mLine.isActive())
{
this.mLine.stop();
return true;
}
return false;
}
public static void main(String args[]) throws InterruptedException
{
if(args.length != 1)
throw new IllegalArgumentException("illegal arguments passed");
Audio audio = new Audio(args[0]);
audio.start();
Thread.sleep(10 * 1000);
audio.stop();
}
}//end class Audio
导致问题的行是第 104 行:
mLine.start();
当我检查调试器时,mLine 对象(SourceDataLine 对象)在执行该行之前一直正常,这会导致 mLine 等于“null”。
我认为这个问题和here是一样的.
我还尝试使用 Clip 而不是 SourceDataLine,但最终遇到了相同的问题。
有趣的是,这个问题并没有发生在 original Xuggler program 中。 ,并且调用 start() 并没有产生那么糟糕的效果。
最佳答案
您有一个成员变量 mLine 和一个局部变量 mLine。只有后者才会被分配。当它超出范围时,您在调试器中看到的是成员变量,它仍然为空。
关于java - SourceDataLine.start() 将对象清空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12503719/
我有一个 QVariantList。我怎样才能清空它。 我试过了 myList.clear() 和 myList.empty(); 但运气不好。有什么想法吗? 最佳答案 A QVariantList只
我在创建一个空的 JTabbedPane 时遇到问题,其中在 GUI 上唯一可见的部分是选项卡行。 每次我添加一个带有“空”组件的新选项卡时,JTabbedPane 的高度都会增加,但这是为什么呢?
我有一个简单的 Windows 窗体,其中包含一个名为 list 的 ListView 对象。在窗体上,一个按钮使我能够在单击 list.Items.Clear() 时清空列表。这很好用。 现在我有一
最近遇到一点麻烦事,新安装的PHPwind6.0正式版社区在导入之前的会员帐号资料时,发现很多会员的mail地址貌似胡乱填写的,之前的PHPwind5.5版本没有开启mail地址验证功能,所以估计很
我在 Visual Basic for Applications 中遇到一个 Collection 对象问题(我在 Excel 中使用它) 我有这段代码试图清空一个我必须重新使用的 Collectio
我想清空 CKEditor 中的文本区域。 我可以使用 SetData(' ') 清除 TextArea,但只能在页面加载后清除一次。 我只在 Onchange 事件中编写了 jquery 函数。
使用 iOS6 的很棒的新 UICollectionView 我如何能够删除一个大循环中的所有 UICollectionViewCell 对象? 假设我已经将所有数据加载到其中,我点击刷新,我想删除那
有没有办法在不诉诸目标的情况下删除 ItemGroup 的内容?我正在寻找相当于: 谢谢 最佳答案 不可以,正如文档所述,Remove 只能包含在 Target 内的 ItemGroup 中
我想清除数组对象中的所有元素(可以是标准的 PHP 数组、ArrayObject 或基本上实现基本数组接口(interface)的任何其他对象,如 Itertable、ArrayAccess、Coun
我有一个 9x9 的网格布局,并生成 Jtextareas 来填充它。如果用户按下按钮,我希望网格布局再次变空,以便我可以再次填充它,但与之前填充的内容无关。是否有某种命令,例如 gridlayout
使用 iOS6 的很棒的新 UICollectionView 我如何能够删除一个大循环中的所有 UICollectionViewCell 对象? 假设我已经将所有数据加载到其中,我点击刷新,我想删除那
我正在尝试在 Eclipse 中使用 Nutch 运行爬网。 我正在使用一个名为 urls 的文件,它包含 http://www.google.com/ 但是,当我运行该项目时,Generator 类
$(document).ready(function () { $('#btnSearch').bind('click', function () {
我有一个 jquery 函数,它在单击事件时清空一个 div,获取一些 json,然后附加到已清除的 div。但是,我试图附加到所述 div 的复选框没有出现。这是我的代码: $(function()
我见过类似的问题,但没有一个和我的完全一样,而且我无法理解答案,所以我希望你能帮助我。 thread我指的是以某种方式解决了异步任务或其他问题,但我不确定那是什么。我的问题是我的布局有一个 TextV
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
一些事实: - 我的应用程序是客户端。 - 我有一个Socket 池。 - 多个 Thread 使用此池。 - 每个线程都可以超时。 - 超时时,Socket 返回到池中,即使没有从服务器读取回复。
请考虑以下代码,包括两个线程 buffering_thread(用一条消息填充缓冲区指针)和 sending_thread(清空缓冲区): #include "msg.cpp" msg * buffe
我制作了这个板,以随机顺序附加了一些框。 当单击按钮时,我想以新的随机顺序附加框,但显然不起作用(.board 保持为空) http://jsbin.com/pedanobawe/2/edit?htm
我有一个脚本,它将文件列表存储在一个数组中,如下所示 set -A my_array $(ls -tr $INPUT_DIRECTORY/*) 我必须清空这个 my_array 变量才能将其用于其他目
我是一名优秀的程序员,十分优秀!