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:
32
src/api-impl-jni/audio/android_media_SoundPool.c
Normal file
32
src/api-impl-jni/audio/android_media_SoundPool.c
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "../defines.h"
|
||||
#include "../generated_headers/android_media_SoundPool.h"
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_android_media_SoundPool_native_1constructor(JNIEnv *env, jclass) {
|
||||
GArray *sound_pool_array = g_array_new(FALSE, FALSE, sizeof(GtkMediaStream *));
|
||||
return _INTPTR(sound_pool_array);
|
||||
}
|
||||
|
||||
static void on_prepared(GtkMediaStream *media_stream) {
|
||||
// play once muted to ensure file is fully loaded
|
||||
gtk_media_stream_set_muted(media_stream, TRUE);
|
||||
gtk_media_stream_play(media_stream);
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_android_media_SoundPool_nativeLoad(JNIEnv *env, jclass, jlong pool, jstring path) {
|
||||
GArray *sound_pool_array = _PTR(pool);
|
||||
const char* nativePath = (*env)->GetStringUTFChars(env, path, NULL);
|
||||
GtkMediaStream *media_stream = gtk_media_file_new_for_filename(nativePath);
|
||||
g_signal_connect(media_stream, "notify::prepared", G_CALLBACK(on_prepared), NULL);
|
||||
(*env)->ReleaseStringUTFChars(env, path, nativePath);
|
||||
return g_array_append_val(sound_pool_array, media_stream)->len - 1;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_android_media_SoundPool_nativePlay(JNIEnv *env, jclass, jlong pool, jint soundID) {
|
||||
GArray *sound_pool_array = _PTR(pool);
|
||||
GtkMediaStream *media_stream = g_array_index(sound_pool_array, GtkMediaStream *, soundID);
|
||||
gtk_media_stream_set_muted(media_stream, FALSE);
|
||||
gtk_media_stream_play(media_stream);
|
||||
return 0;
|
||||
}
|
||||
37
src/api-impl-jni/generated_headers/android_media_SoundPool.h
Normal file
37
src/api-impl-jni/generated_headers/android_media_SoundPool.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class android_media_SoundPool */
|
||||
|
||||
#ifndef _Included_android_media_SoundPool
|
||||
#define _Included_android_media_SoundPool
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: android_media_SoundPool
|
||||
* Method: native_constructor
|
||||
* Signature: ()J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL Java_android_media_SoundPool_native_1constructor
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: android_media_SoundPool
|
||||
* Method: nativeLoad
|
||||
* Signature: (JLjava/lang/String;)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_android_media_SoundPool_nativeLoad
|
||||
(JNIEnv *, jclass, jlong, jstring);
|
||||
|
||||
/*
|
||||
* Class: android_media_SoundPool
|
||||
* Method: nativePlay
|
||||
* Signature: (JI)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_android_media_SoundPool_nativePlay
|
||||
(JNIEnv *, jclass, jlong, jint);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
Reference in New Issue
Block a user