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

The following examples show how to use com.jme3.audio.AudioNode#setChannel() . 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: AndroidAudioRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
    AudioNode src = mapLoadingAudioNodes.get(sampleId);
    if (src.getAudioData() instanceof AndroidAudioData) {
        AndroidAudioData audioData = (AndroidAudioData) src.getAudioData();

        if (status == 0) // load was successfull
        {
            int channelIndex;
            channelIndex = soundPool.play(audioData.getId(), 1f, 1f, 1, -1, 1f);
            src.setChannel(channelIndex);
            // Playing started ?
            if (src.getChannel() > 0) {
                src.setStatus(Status.Playing);
            }
        } else {
            src.setChannel(-1);
        }
    } else {
        throw new IllegalArgumentException("AudioData is not of type AndroidAudioData for AudioNode " + src.toString());
    }
}
 
Example 2
Source File: AndroidAudioRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void deleteAudioData(AudioData ad) {
    if (ad instanceof AndroidAudioData) {
        AndroidAudioData audioData = (AndroidAudioData) ad;
        if (audioData.getAssetKey() instanceof AudioKey) {
            AudioKey assetKey = (AudioKey) audioData.getAssetKey();
            if (assetKey.isStream()) {
                for (AudioNode src : musicPlaying.keySet()) {
                    if (src.getAudioData() == ad) {
                        MediaPlayer mp = musicPlaying.get(src);
                        mp.stop();
                        mp.release();
                        musicPlaying.remove(src);
                        src.setStatus(Status.Stopped);
                        src.setChannel(-1);
                        break;
                    }
                }
            } else {
                if (audioData.getId() > 0) {
                    soundPool.unload(audioData.getId());
                }
                audioData.setId(0);
            }

        }
    } else {
        throw new IllegalArgumentException("AudioData is not of type AndroidAudioData in deleteAudioData");
    }
}
 
Example 3
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);
    }
}