Commit 44582073 authored by Adrien Maglo's avatar Adrien Maglo

Libvlcjni and vlc-android changes and additions to display video output.

parent 48ea622d
#include <stdio.h>
#include <string.h>
#include <android/native_window_jni.h>
#include <jni.h>
#include <vlc/vlc.h>
#include "libvlcjni.h"
jint Java_vlc_android_libVLC_init(JNIEnv *env, jobject thiz)
// Native android window to display the video.
ANativeWindow *p_nativeWindow;
void Java_vlc_android_LibVLC_setSurface(JNIEnv *env, jobject thiz, jobject surface)
{
const char *argv[] = { "-I dummy", "-vvv", "--no-plugins-cache" };
return (jint)libvlc_new_with_builtins( 3, argv, vlc_builtins_modules );
p_nativeWindow = ANativeWindow_fromSurface(env, surface);
}
void Java_vlc_android_libVLC_destroy(JNIEnv *env, jobject thiz, jint instance)
jint Java_vlc_android_LibVLC_init(JNIEnv *env, jobject thiz)
{
char psz_pWin[255];
snprintf(psz_pWin, 255, "%i", p_nativeWindow);
const char *argv[] = {"-I", "dummy", "-vvv", "--no-plugins-cache",
"--no-audio", "--no-drop-late-frames",
"--vout", "egl_android",
"--egl-android-window", psz_pWin};
return (jint)libvlc_new_with_builtins(10, argv, vlc_builtins_modules);
}
void Java_vlc_android_LibVLC_destroy(JNIEnv *env, jobject thiz, jint instance)
{
libvlc_instance_t *p_instance = (libvlc_instance_t*)instance;
libvlc_release(p_instance);
}
void Java_vlc_android_libVLC_readMedia(JNIEnv *env, jobject thiz, jint instance)
void Java_vlc_android_LibVLC_readMedia(JNIEnv *env, jobject thiz, jint instance,
jstring mrl)
{
jboolean isCopy;
const char *psz_mrl = (*env)->GetStringUTFChars(env, mrl, &isCopy);
/* Create a new item */
libvlc_media_t *m = libvlc_media_new_path((libvlc_instance_t*)instance, "/sdcard/test.mp3");
libvlc_media_t *m = libvlc_media_new_path((libvlc_instance_t*)instance,
psz_mrl);
/* Create a media player playing environement */
libvlc_media_player_t *mp = libvlc_media_player_new_from_media(m);
......@@ -28,24 +52,25 @@ void Java_vlc_android_libVLC_readMedia(JNIEnv *env, jobject thiz, jint instance)
/* No need to keep the media now */
libvlc_media_release(m);
/* Play the media. */
libvlc_media_player_play(mp);
sleep(10000);
//libvlc_media_player_release(mp);
libvlc_media_player_release(mp);
(*env)->ReleaseStringUTFChars(env, mrl, psz_mrl);
}
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());
}
jstring Java_vlc_android_libVLC_compiler(JNIEnv* env, jobject thiz)
jstring Java_vlc_android_LibVLC_compiler(JNIEnv* env, jobject thiz)
{
return (*env)->NewStringUTF(env, libvlc_get_compiler());
}
jstring Java_vlc_android_libVLC_changeset(JNIEnv* env, jobject thiz)
jstring Java_vlc_android_LibVLC_changeset(JNIEnv* env, jobject thiz)
{
return (*env)->NewStringUTF(env, libvlc_get_changeset());
}
......@@ -4,11 +4,10 @@
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView android:id="@+id/text_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Button android:id="@+id/button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Read /sdcard/test.mp3" />
<Button android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/button" android:text="Read /sdcard/test.mp4"></Button>
<SurfaceView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/surface_view"></SurfaceView>
</LinearLayout>
package vlc.android;
public class libVLC {
import android.view.Surface;
public class LibVLC {
/**
* Constructor
*/
public libVLC()
public LibVLC()
{
System.loadLibrary("vlcjni");
};
......@@ -17,6 +19,12 @@ public class libVLC {
if(this.p_instance != 0)
this.destroy(p_instance);
}
/**
* Give to libvlc the surface to draw the video.
* @param f: the surface to draw
*/
public native void setSurface(Surface f);
/**
* Initialize the libVLC class
......@@ -31,11 +39,10 @@ public class libVLC {
/**
* Read a media.
*/
public void readMedia()
public void readMedia(String mrl)
{
readMedia(p_instance);
readMedia(p_instance, mrl);
}
/** libVLC instance C pointer */
private int p_instance;
......@@ -55,8 +62,9 @@ public class libVLC {
/**
* Read a media
* @param instance: the instance of libVLC
* @param mrl: the media mrl
*/
private native void readMedia(int instance);
private native void readMedia(int instance, String mrl);
/**
* Get the libVLC version
......
package vlc.android;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
public class SurfaceCallback implements Callback {
public SurfaceCallback(LibVLC l) {
libvlc = l;
}
@Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
// Give the surface to draw the video to libVLC
libvlc.setSurface(holder.getSurface());
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
}
private LibVLC libvlc;
}
......@@ -3,12 +3,11 @@ package vlc.android;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Button;
import android.view.SurfaceView;
import android.view.View;
import java.lang.*;
public class vlc extends Activity {
/** Called when the activity is first created. */
......@@ -17,29 +16,20 @@ public class vlc extends Activity {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TextView tv = (TextView)findViewById(R.id.text_view);
final Button button = (Button)findViewById(R.id.button);
// Create the libVLC instance
libvlc = new libVLC();
if(libvlc.Init())
tv.setText("Loaded libVLC:\n* version: " + libvlc.version() +
"\n* compiler: " + libvlc.compiler() +
"\n* changeset: " + libvlc.changeset() +
"\n* libvlccore loaded\n");
else
tv.setText("Loaded libVLC:\n* version: " + libvlc.version() +
"\n* compiler: " + libvlc.compiler() +
"\n* changeset: " + libvlc.changeset() +
"\n* libvlccore failed!!!\n");
final SurfaceView surfaceView = (SurfaceView)findViewById(R.id.surface_view);
libvlc = new LibVLC();
surfaceView.getHolder().addCallback(new SurfaceCallback(libvlc));
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
libvlc.readMedia();
libvlc.Init();
libvlc.readMedia("/sdcard/test.mp4");
}
});
}
libVLC libvlc;
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