Audio

Class of snx.android.media · Audio.java

public final class Audio

The runtime's audio (src/android/runtime/audio.c), which MediaPlayer and SoundPool play through: a source's bytes, read here, are decoded by FFmpeg, and one SDL audio stream mixes the voices. A voice is an ID: a sound's (which ends by itself) or a stream's (a player's, which stays paused at its end). A thread tells each watched voice's end.

Members

public static final int PAUSE = 0 source
public static final int RESUME = 1 source
public static final int STOP = 2 source
public static final int VOLUME = 3 source
public static final int LOOPS = 4 source
public static final int RATE = 5 source
public static final int SEEK = 6 source
public static native long nativeLoad(byte[] data) native source

a sound decoded whole, 0 when the source holds no audio that the runtime decodes

public static native void nativeUnload(long sound) native source

the sound given up; the voices that play it keep it to their end

public static native int nativePlay(long sound, float left, float right, int loops, float rate) native source

a voice of the sound, 0 when none plays: loops more plays after the first, -1 for ever

public static native int nativeOpen(byte[] data, long[] duration) native source

a paused voice of a stream, decoded as it plays, and its length in milliseconds (-1 unknown) in duration[0]

public static native void nativeSet(int voice, int what, double x, double y) native source

the voice paused, resumed, stopped, its volumes (x, y), loops (x), rate (x) or position in milliseconds (x)

public static native long nativePosition(int voice, boolean[] completed) native source

the voice's position in milliseconds, -1 when it is gone: completed[0] tells once that it reached its end

public static void set(int voice, int what, double x, double y) source
public static void set(int voice, int what) source
public static float volume(float v) source

The sources

public static byte[] read(InputStream in) throws IOException source
public static byte[] read(String path) throws IOException source
public static byte[] read(Context context, int resId) throws IOException source
public static byte[] read(FileDescriptor fd, long offset, long length) throws IOException source

length bytes from offset (to the end for a negative or too large length), the descriptor left open

public static byte[] read(Context context, Uri uri) throws IOException source

a file:, android.resource: or content: URI's bytes, or a path's

The ends of watched voices

public static synchronized void watch(int voice, Runnable onEnd) source

onEnd run (on the watcher's thread) each time the voice reaches its end, until the voice is gone or unwatched

public static synchronized void unwatch(int voice) source

Made from ScarletNX's Sail at 166ad3910f80. The framework is ScarletNX's (GPL-3.0-or-later); the parts that follow the Android Open Source Project's sources (Apache-2.0) say so in their files.