Search in sources :

Example 1 with AndroidAssetInfo

use of com.jme3.asset.plugins.AndroidLocator.AndroidAssetInfo in project jmonkeyengine by jMonkeyEngine.

the class NativeVorbisLoader method loadStream.

private static AudioStream loadStream(AssetInfo assetInfo) throws IOException {
    AndroidAssetInfo aai = (AndroidAssetInfo) assetInfo;
    AssetFileDescriptor afd = null;
    NativeVorbisFile file = null;
    boolean success = false;
    try {
        afd = aai.openFileDescriptor();
        int fd = afd.getParcelFileDescriptor().getFd();
        file = new NativeVorbisFile(fd, afd.getStartOffset(), afd.getLength());
        AudioStream stream = new AudioStream();
        stream.setupFormat(file.channels, 16, file.sampleRate);
        stream.updateData(new VorbisInputStream(afd, file), file.duration);
        success = true;
        return stream;
    } finally {
        if (!success) {
            if (file != null) {
                file.close();
            }
            if (afd != null) {
                afd.close();
            }
        }
    }
}
Also used : AudioStream(com.jme3.audio.AudioStream) AssetFileDescriptor(android.content.res.AssetFileDescriptor) AndroidAssetInfo(com.jme3.asset.plugins.AndroidLocator.AndroidAssetInfo)

Example 2 with AndroidAssetInfo

use of com.jme3.asset.plugins.AndroidLocator.AndroidAssetInfo in project jmonkeyengine by jMonkeyEngine.

the class NativeVorbisLoader method loadBuffer.

private static AudioBuffer loadBuffer(AssetInfo assetInfo) throws IOException {
    AndroidAssetInfo aai = (AndroidAssetInfo) assetInfo;
    AssetFileDescriptor afd = null;
    NativeVorbisFile file = null;
    try {
        afd = aai.openFileDescriptor();
        int fd = afd.getParcelFileDescriptor().getFd();
        file = new NativeVorbisFile(fd, afd.getStartOffset(), afd.getLength());
        ByteBuffer data = BufferUtils.createByteBuffer(file.totalBytes);
        file.readFully(data);
        AudioBuffer ab = new AudioBuffer();
        ab.setupFormat(file.channels, 16, file.sampleRate);
        ab.updateData(data);
        return ab;
    } finally {
        if (file != null) {
            file.close();
        }
        if (afd != null) {
            afd.close();
        }
    }
}
Also used : AssetFileDescriptor(android.content.res.AssetFileDescriptor) AudioBuffer(com.jme3.audio.AudioBuffer) AndroidAssetInfo(com.jme3.asset.plugins.AndroidLocator.AndroidAssetInfo) ByteBuffer(java.nio.ByteBuffer)

Aggregations

AssetFileDescriptor (android.content.res.AssetFileDescriptor)2 AndroidAssetInfo (com.jme3.asset.plugins.AndroidLocator.AndroidAssetInfo)2 AudioBuffer (com.jme3.audio.AudioBuffer)1 AudioStream (com.jme3.audio.AudioStream)1 ByteBuffer (java.nio.ByteBuffer)1