Skip to content

seek, get_pos and get_length support for mediaplayer #106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 11, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion recipes/android/src/android_mixer.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ def play(self, s, loops=0, maxtime=0, fade_ms=0):
with condition:
condition.notify()

def seek(self, position):
sound.seek(self.id, position)

def stop(self):
self.loop = None
Expand Down Expand Up @@ -159,6 +161,12 @@ def queue(self, s):
def get_queue(self):
return self.queued

def get_pos(self):
return sound.get_pos(self.id)/1000.

def get_length(self):
return sound.get_length(self.id)/1000.


def Channel(n):
"""
Expand Down Expand Up @@ -205,6 +213,7 @@ def play(self, loops=0, maxtime=0, fade_ms=0):
channel.play(self, loops=loops)
return channel


def stop(self):
for i in range(0, num_channels):
if Channel(i).get_sound() is self:
Expand Down Expand Up @@ -254,6 +263,10 @@ def play(loops=0, start=0.0):
def rewind():
music_channel.play(music_sound)

@staticmethod
def seek(position):
music_channel.seek(position)

@staticmethod
def stop():
music_channel.stop()
Expand Down Expand Up @@ -284,7 +297,7 @@ def get_busy():

@staticmethod
def get_pos():
return 0
return music_channel.get_pos()

@staticmethod
def queue(filename):
Expand Down
21 changes: 15 additions & 6 deletions recipes/android/src/android_sound.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cdef extern void android_sound_queue(int, char *, char *, long long, long long)
cdef extern void android_sound_play(int, char *, char *, long long, long long)
cdef extern void android_sound_stop(int)
cdef extern void android_sound_seek(int, float)
cdef extern void android_sound_dequeue(int)
cdef extern void android_sound_playing_name(int, char *, int)
cdef extern void android_sound_pause(int)
Expand All @@ -11,15 +12,17 @@ cdef extern void android_sound_set_secondary_volume(int, float)
cdef extern void android_sound_set_pan(int, float)

cdef extern int android_sound_queue_depth(int)
cdef extern int android_sound_get_pos(int)
cdef extern int android_sound_get_length(int)

channels = set()
volumes = { }

def queue(channel, file, name, fadein=0, tight=False):

channels.add(channel)
real_fn = file.name

real_fn = file.name
base = getattr(file, "base", -1)
length = getattr(file, "length", -1)

Expand All @@ -28,13 +31,16 @@ def queue(channel, file, name, fadein=0, tight=False):
def play(channel, file, name, paused=False, fadein=0, tight=False):

channels.add(channel)

real_fn = file.name
base = getattr(file, "base", -1)
length = getattr(file, "length", -1)

android_sound_play(channel, name, real_fn, base, length)

def seek(channel, position):
android_sound_seek(channel, position)

def stop(channel):
android_sound_stop(channel)

Expand Down Expand Up @@ -70,20 +76,23 @@ def unpause_all():
def pause_all():
for i in channels:
pause(i)

def fadeout(channel, ms):
stop(channel)

def busy(channel):
return playing_name(channel) != None

def get_pos(channel):
return 0
return android_sound_get_pos(channel)

def get_length(channel):
return android_sound_get_length(channel)

def set_volume(channel, volume):
android_sound_set_volume(channel, volume)
volumes[channel] = volume

def set_secondary_volume(channel, volume):
android_sound_set_secondary_volume(channel, volume)

Expand Down
70 changes: 64 additions & 6 deletions recipes/android/src/android_sound_jni.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ void android_sound_queue(int channel, char *filename, char *real_fn, long long b
}

PUSH_FRAME;

(*env)->CallStaticVoidMethod(
env, cls, mid,
channel,
(*env)->NewStringUTF(env, filename),
(*env)->NewStringUTF(env, real_fn),
(jlong) base,
(jlong) length);
(jlong) length);

POP_FRAME;
}
Expand All @@ -41,7 +41,7 @@ void android_sound_play(int channel, char *filename, char *real_fn, long long ba
static JNIEnv *env = NULL;
static jclass *cls = NULL;
static jmethodID mid = NULL;

if (env == NULL) {
env = SDL_ANDROID_GetJNIEnv();
aassert(env);
Expand All @@ -52,7 +52,7 @@ void android_sound_play(int channel, char *filename, char *real_fn, long long ba
}

PUSH_FRAME;

(*env)->CallStaticVoidMethod(
env, cls, mid,
channel,
Expand All @@ -64,6 +64,26 @@ void android_sound_play(int channel, char *filename, char *real_fn, long long ba
POP_FRAME;
}

void android_sound_seek(int channel, float position){
static JNIEnv *env = NULL;
static jclass *cls = NULL;
static jmethodID mid = NULL;

if (env == NULL) {
env = SDL_ANDROID_GetJNIEnv();
aassert(env);
cls = (*env)->FindClass(env, "org/renpy/android/RenPySound");
aassert(cls);
mid = (*env)->GetStaticMethodID(env, cls, "seek", "(IF)V");
aassert(mid);
}

(*env)->CallStaticVoidMethod(
env, cls, mid,
channel,
(jfloat) position);
}

void android_sound_stop(int channel) {
static JNIEnv *env = NULL;
static jclass *cls = NULL;
Expand Down Expand Up @@ -128,7 +148,7 @@ void android_sound_playing_name(int channel, char *buf, int buflen) {

jobject s = NULL;
char *jbuf;

if (env == NULL) {
env = SDL_ANDROID_GetJNIEnv();
aassert(env);
Expand All @@ -139,7 +159,7 @@ void android_sound_playing_name(int channel, char *buf, int buflen) {
}

PUSH_FRAME;

s = (*env)->CallStaticObjectMethod(
env, cls, mid,
channel);
Expand Down Expand Up @@ -248,3 +268,41 @@ void android_sound_unpause(int channel) {
env, cls, mid,
channel);
}

int android_sound_get_pos(int channel) {
static JNIEnv *env = NULL;
static jclass *cls = NULL;
static jmethodID mid = NULL;

if (env == NULL) {
env = SDL_ANDROID_GetJNIEnv();
aassert(env);
cls = (*env)->FindClass(env, "org/renpy/android/RenPySound");
aassert(cls);
mid = (*env)->GetStaticMethodID(env, cls, "get_pos", "(I)I");
aassert(mid);
}

(*env)->CallStaticIntMethod(
env, cls, mid,
channel);
}

int android_sound_get_length(int channel) {
static JNIEnv *env = NULL;
static jclass *cls = NULL;
static jmethodID mid = NULL;

if (env == NULL) {
env = SDL_ANDROID_GetJNIEnv();
aassert(env);
cls = (*env)->FindClass(env, "org/renpy/android/RenPySound");
aassert(cls);
mid = (*env)->GetStaticMethodID(env, cls, "get_length", "(I)I");
aassert(mid);
}

(*env)->CallStaticIntMethod(
env, cls, mid,
channel);
}
Loading