You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
implement android.media.SoundPool using GtkMediaStream
This commit is contained in:
@@ -42,6 +42,7 @@ public class AssetFileDescriptor implements Closeable {
|
||||
private final long mStartOffset;
|
||||
private final long mLength;
|
||||
private final Bundle mExtras;
|
||||
public String fileName;
|
||||
|
||||
/**
|
||||
* Create a new AssetFileDescriptor from the given values.
|
||||
|
||||
@@ -27,7 +27,7 @@ import android.os.ParcelFileDescriptor;
|
||||
import android.os.Trace;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -329,18 +329,22 @@ public final class AssetManager {
|
||||
|
||||
public final AssetFileDescriptor openFd(String fileName)
|
||||
throws IOException {
|
||||
/* synchronized (this) {
|
||||
int asset;
|
||||
synchronized (this) {
|
||||
if (!mOpen) {
|
||||
throw new RuntimeException("Assetmanager has been closed");
|
||||
}
|
||||
ParcelFileDescriptor pfd = openAssetFd(fileName, mOffsets);
|
||||
asset = openAsset(fileName, 0);
|
||||
FileDescriptor fd = new FileDescriptor();
|
||||
fd.setInt$(asset);
|
||||
ParcelFileDescriptor pfd = new ParcelFileDescriptor(fd);
|
||||
if (pfd != null) {
|
||||
return new AssetFileDescriptor(pfd, mOffsets[0], mOffsets[1]);
|
||||
AssetFileDescriptor afd = new AssetFileDescriptor(pfd, mOffsets[0], mOffsets[1]);
|
||||
afd.fileName = "/assets/" + fileName;
|
||||
return afd;
|
||||
}
|
||||
}
|
||||
throw new FileNotFoundException("Asset file: " + fileName);*/
|
||||
throw new IOException("FIXME: 'public final AssetFileDescriptor openFd(String fileName)': throwing an exception, which makes e.g SDL2 fall back to using something that we actually have implemented");
|
||||
// return null; // FIXME
|
||||
throw new FileNotFoundException("Asset file: " + fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,10 +3,40 @@ package android.media;
|
||||
import android.content.res.AssetFileDescriptor;
|
||||
|
||||
public class SoundPool {
|
||||
|
||||
private long nativePool;
|
||||
|
||||
public interface OnLoadCompleteListener {
|
||||
/**
|
||||
* Called when a sound has completed loading.
|
||||
*
|
||||
* @param soundPool SoundPool object from the load() method
|
||||
* @param soundPool the sample ID of the sound loaded.
|
||||
* @param status the status of the load operation (0 = success)
|
||||
*/
|
||||
public void onLoadComplete(SoundPool soundPool, int sampleId, int status);
|
||||
}
|
||||
|
||||
public SoundPool (int maxStreams, int streamType, int srcQuality) {
|
||||
nativePool = native_constructor();
|
||||
}
|
||||
|
||||
public int load(AssetFileDescriptor afd, int priority) {
|
||||
return 0;
|
||||
return nativeLoad(nativePool, android.os.Environment.getExternalStorageDirectory().getPath() + afd.fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the callback hook for the OnLoadCompleteListener.
|
||||
*/
|
||||
public void setOnLoadCompleteListener(OnLoadCompleteListener listener) {
|
||||
System.out.println("WARNING: SoundPool.setOnLoadCompleteListener not implemented yet");
|
||||
}
|
||||
|
||||
public final int play(int soundID, float leftVolume, float rightVolume, int priority, int loop, float rate) {
|
||||
return nativePlay(nativePool, soundID);
|
||||
}
|
||||
|
||||
private static native long native_constructor();
|
||||
private static native int nativeLoad(long nativePool, String path);
|
||||
public static native int nativePlay(long nativePool, int soundID);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user