Commit f3db2e4a authored by Adrien Maglo's avatar Adrien Maglo

Add a basic interface based on Android internal media controller widget to control the playback.

parent e425f902
......@@ -217,6 +217,14 @@ void Java_vlc_android_LibVLC_readMedia(JNIEnv *env, jobject thiz,
(*env)->ReleaseStringUTFChars(env, mrl, psz_mrl);
}
jboolean Java_vlc_android_LibVLC_hasMediaPlayer(JNIEnv *env, jobject thiz)
{
jint mediaPlayer = getMediaPlayer(env, thiz);
if (mediaPlayer != 0)
return 1;
return 0;
}
jboolean Java_vlc_android_LibVLC_isPlaying(JNIEnv *env, jobject thiz)
{
jint mediaPlayer = getMediaPlayer(env, thiz);
......@@ -225,6 +233,7 @@ jboolean Java_vlc_android_LibVLC_isPlaying(JNIEnv *env, jobject thiz)
libvlc_media_player_t *mp = (libvlc_media_player_t*) mediaPlayer;
return ( libvlc_media_player_is_playing( mp ) == 1 );
}
return 0;
}
jboolean Java_vlc_android_LibVLC_isSeekable(JNIEnv *env, jobject thiz)
......@@ -235,6 +244,7 @@ jboolean Java_vlc_android_LibVLC_isSeekable(JNIEnv *env, jobject thiz)
libvlc_media_player_t *mp = (libvlc_media_player_t*) mediaPlayer;
return ( libvlc_media_player_is_seekable( mp ) == 1 );
}
return 0;
}
void Java_vlc_android_LibVLC_play(JNIEnv *env, jobject thiz)
......
......@@ -135,8 +135,6 @@ public class LibVLC {
{
return getThumbnail(mLibVlcInstance, filePath, i_width, i_height);
}
/**
* Initialize the libvlc C library
......@@ -157,6 +155,11 @@ public class LibVLC {
*/
private native void readMedia(int instance, String mrl);
/**
* Return true if there is currently a running media player.
*/
public native boolean hasMediaPlayer();
/**
* Returns true if any media is playing
*/
......
......@@ -10,6 +10,7 @@ import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.widget.Button;
import android.widget.MediaController;
import android.util.Log;
import android.view.Menu;
......@@ -28,6 +29,8 @@ public class VLC extends Activity {
private LibVLC mLibVlc;
private SurfaceView mSurfaceViewVideo;
private SurfaceHolder mSurfaceHolderVideo;
private MediaController controller;
/** Called when the activity is first created. */
@Override
......@@ -50,14 +53,22 @@ public class VLC extends Activity {
mSurfaceViewVideo = (SurfaceView) findViewById(R.id.surface_view);
mSurfaceHolderVideo = mSurfaceViewVideo.getHolder();
mSurfaceViewVideo.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
controller.show(10000);
}
});
mLibVlc = LibVLC.getInstance();
controller = new MediaController(this);
controller.setMediaPlayer(playerInterface);
controller.setAnchorView(mSurfaceViewVideo);
mSurfaceHolderVideo.addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceCreated(SurfaceHolder holder) {
}
@Override
......@@ -167,8 +178,59 @@ public class VLC extends Activity {
Bundle extras = data.getExtras();
if (requestCode == 0 && resultCode == RESULT_OK) {
controller.hide();
String filePath = extras.getString("filePath");
mLibVlc.readMedia(filePath);
}
}
// Implement the MediaController.MediaPlayerControl interface
private MediaController.MediaPlayerControl playerInterface = new MediaController.MediaPlayerControl()
{
public int getBufferPercentage() {
return 0;
}
public int getCurrentPosition() {
float pos = mLibVlc.getPosition();
return (int)(pos * getDuration());
}
public int getDuration() {
return (int)mLibVlc.getLength();
}
public boolean isPlaying() {
return mLibVlc.isPlaying();
}
public void pause() {
mLibVlc.pause();
}
public void seekTo(int pos) {
mLibVlc.setPosition((float)pos / getDuration());
}
public void start() {
if (mLibVlc.hasMediaPlayer())
mLibVlc.play();
else {
Intent i = new Intent(VLC.this, SimpleFileBrowser.class);
startActivityForResult(i, 0);
}
}
public boolean canPause() {
return true;
}
public boolean canSeekBackward() {
return true;
}
public boolean canSeekForward() {
return true;
}
};
}
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