Java Code Examples for com.jme3.audio.AudioNode#getStatus()

The following examples show how to use com.jme3.audio.AudioNode#getStatus() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AudioViewer3DPart.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Remove the current audio node.
 */
@JmeThread
private void removeAudioNode() {

    final AudioNode currentAudioNode = getAudioNode();
    if (currentAudioNode == null) {
        return;
    }

    final Node stateNode = getStateNode();
    final Status status = currentAudioNode.getStatus();

    if (status == Status.Playing || status == Status.Paused) {
        currentAudioNode.stop();
    }

    stateNode.detachChild(currentAudioNode);

    setAudioNode(null);
    setPrevStatus(null);
}
 
Example 2
Source File: AudioViewer3DPart.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Play the current audio.
 */
@JmeThread
private void playImpl() {

    final AudioNode currentAudioNode = getAudioNode();

    if (currentAudioNode != null) {

        final Status status = currentAudioNode.getStatus();

        if (status == Status.Paused) {
            currentAudioNode.play();
            return;
        } else if (status == Status.Playing) {
            return;
        }
    }

    loadImpl(getAudioData(), getAudioKey());

    final AudioNode audioNode = getAudioNode();
    audioNode.play();
}
 
Example 3
Source File: AudioTreeNode.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
@Override
@FxThread
public void fillContextMenu(@NotNull final NodeTree<?> nodeTree, @NotNull final ObservableList<MenuItem> items) {
    if (!(nodeTree instanceof ModelNodeTree)) return;

    final AudioNode element = getElement();
    final AudioData audioData = element.getAudioData();
    final AudioSource.Status status = element.getStatus();

    if (audioData != null && status != AudioSource.Status.Playing) {
        items.add(new PlayAudioNodeAction(nodeTree, this));
    } else if (audioData != null) {
        items.add(new StopAudioNodeAction(nodeTree, this));
    }

    super.fillContextMenu(nodeTree, items);
}
 
Example 4
Source File: AudioViewer3DPart.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@JmeThread
public void update(final float tpf) {
    super.update(tpf);

    final AudioNode audioNode = getAudioNode();
    if (audioNode == null) return;

    final Status status = audioNode.getStatus();
    if (status != getPrevStatus()) {
        EXECUTOR_MANAGER.addFxTask(() -> getFileEditor().notifyChangedStatus(status));
        setPrevStatus(status);
    }
}
 
Example 5
Source File: AndroidAudioRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void playSource(AudioNode src) {
    if (audioDisabled) {
        return;
    }

    //assert src.getStatus() == Status.Stopped || src.getChannel() == -1;

    if (src.getStatus() == Status.Playing) {
        return;
    } else if (src.getStatus() == Status.Stopped) {
        playSourceInstance(src);
    }


}
 
Example 6
Source File: LwjglAudioRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void playSource(AudioNode src) {
    checkDead();
    synchronized (threadLock){
        while (!threadLock.get()){
            try {
                threadLock.wait();
            } catch (InterruptedException ex) {
            }
        }
        if (audioDisabled)
            return;

        //assert src.getStatus() == Status.Stopped || src.getChannel() == -1;

        if (src.getStatus() == Status.Playing){
            return;
        }else if (src.getStatus() == Status.Stopped){

            // allocate channel to this source
            int index = newChannel();
            if (index == -1) {
                logger.log(Level.WARNING, "No channel available to play {0}", src);
                return;
            }
            clearChannel(index);
            src.setChannel(index);

            AudioData data = src.getAudioData();
            if (data.isUpdateNeeded())
                updateAudioData(data);

            chanSrcs[index] = src;
            setSourceParams(channels[index], src, false);
            attachAudioToSource(channels[index], data);
        }

        alSourcePlay(channels[src.getChannel()]);
        src.setStatus(Status.Playing);
    }
}