Commit b09b6249 authored by Adrien Maglo's avatar Adrien Maglo
Browse files

Add a button and methods to read /sdcard/test.mp3

Remove some compilation warning: a native point corresponds to a jint.
parent deb96b28
#include <string.h> #include <string.h>
#include <jni.h> #include <jni.h>
#include <vlc/libvlc.h> #include <vlc/vlc.h>
#include "libvlcjni.h" #include "libvlcjni.h"
jlong Java_vlc_android_libVLC_init(JNIEnv *env, jobject thiz) jint Java_vlc_android_libVLC_init(JNIEnv *env, jobject thiz)
{ {
const char *argv[] = { "-I dummy", "-vvv", "--no-plugins-cache" }; const char *argv[] = { "-I dummy", "-vvv", "--no-plugins-cache" };
return (jlong)libvlc_new_with_builtins( 3, argv, vlc_builtins_modules ); return (jint)libvlc_new_with_builtins( 3, argv, vlc_builtins_modules );
} }
void Java_vlc_android_libVLC_destroy(JNIEnv *env, jobject thiz, jlong instance) void Java_vlc_android_libVLC_destroy(JNIEnv *env, jobject thiz, jint instance)
{ {
libvlc_instance_t *p_instance = (libvlc_instance_t*)instance; libvlc_instance_t *p_instance = (libvlc_instance_t*)instance;
libvlc_release(p_instance); libvlc_release(p_instance);
} }
void Java_vlc_android_libVLC_readMedia(JNIEnv *env, jobject thiz, jint instance)
{
/* Create a new item */
libvlc_media_t *m = libvlc_media_new_path((libvlc_instance_t*)instance, "/sdcard/test.mp3");
/* Create a media player playing environement */
libvlc_media_player_t *mp = libvlc_media_player_new_from_media(m);
/* No need to keep the media now */
libvlc_media_release(m);
libvlc_media_player_play(mp);
sleep(10000);
libvlc_media_player_release(mp);
}
jstring Java_vlc_android_libVLC_version(JNIEnv* env, jobject thiz) jstring Java_vlc_android_libVLC_version(JNIEnv* env, jobject thiz)
{ {
return (*env)->NewStringUTF(env, libvlc_get_version()); return (*env)->NewStringUTF(env, libvlc_get_version());
......
...@@ -4,9 +4,11 @@ ...@@ -4,9 +4,11 @@
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
> >
<TextView <TextView android:id="@+id/text_view"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content" />
android:text="@string/hello" <Button android:id="@+id/button"
/> android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Read /sdcard/test.mp3" />
</LinearLayout> </LinearLayout>
...@@ -27,21 +27,36 @@ public class libVLC { ...@@ -27,21 +27,36 @@ public class libVLC {
this.p_instance = this.init(); this.p_instance = this.init();
return this.p_instance != 0; return this.p_instance != 0;
} }
/**
* Read a media.
*/
public void readMedia()
{
readMedia(p_instance);
}
/** libVLC instance C pointer */ /** libVLC instance C pointer */
private long p_instance; private int p_instance;
/** /**
* Initialize the libvlc C library * Initialize the libvlc C library
* @return a pointer to the libvlc instance * @return a pointer to the libvlc instance
*/ */
private native long init(); private native int init();
/** /**
* Close the libvlc C library * Close the libvlc C library
* @param instance: the instance of libVLC * @param instance: the instance of libVLC
*/ */
private native void destroy(long instance); private native void destroy(int instance);
/**
* Read a media
* @param instance: the instance of libVLC
*/
private native void readMedia(int instance);
/** /**
* Get the libVLC version * Get the libVLC version
......
...@@ -4,6 +4,9 @@ import android.app.Activity; ...@@ -4,6 +4,9 @@ import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Button;
import android.view.View;
import java.lang.*; import java.lang.*;
...@@ -12,11 +15,13 @@ public class vlc extends Activity { ...@@ -12,11 +15,13 @@ public class vlc extends Activity {
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = new TextView(this); final TextView tv = (TextView)findViewById(R.id.text_view);
final Button button = (Button)findViewById(R.id.button);
// Create the libVLC instance // Create the libVLC instance
libVLC libvlc = new libVLC(); libvlc = new libVLC();
if(libvlc.Init()) if(libvlc.Init())
tv.setText("Loaded libVLC:\n* version: " + libvlc.version() + tv.setText("Loaded libVLC:\n* version: " + libvlc.version() +
...@@ -29,6 +34,12 @@ public class vlc extends Activity { ...@@ -29,6 +34,12 @@ public class vlc extends Activity {
"\n* changeset: " + libvlc.changeset() + "\n* changeset: " + libvlc.changeset() +
"\n* libvlccore failed!!!\n"); "\n* libvlccore failed!!!\n");
setContentView(tv); button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
libvlc.readMedia();
}
});
} }
libVLC libvlc;
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment