[Android] LibVLC: replace setSubtitleFile with addSlave
Thomas Guillem
git at videolan.org
Tue May 31 16:24:56 CEST 2016
vlc-android | branch: master | Thomas Guillem <thomas at gllm.fr> | Tue May 31 16:21:11 2016 +0200| [0322085240111b6864bd9a7b2e607cb29e8472a5] | committer: Thomas Guillem
LibVLC: replace setSubtitleFile with addSlave
> https://code.videolan.org/videolan/vlc-android/commit/0322085240111b6864bd9a7b2e607cb29e8472a5
---
libvlc/jni/libvlcjni-mediaplayer.c | 22 +++++++++---------
libvlc/src/org/videolan/libvlc/Media.java | 2 +-
libvlc/src/org/videolan/libvlc/MediaPlayer.java | 26 +++++++++++++++++-----
.../src/org/videolan/libvlc/media/MediaPlayer.java | 5 +++--
.../src/org/videolan/vlc/PlaybackService.java | 7 +++++-
5 files changed, 42 insertions(+), 20 deletions(-)
diff --git a/libvlc/jni/libvlcjni-mediaplayer.c b/libvlc/jni/libvlcjni-mediaplayer.c
index 689fa48..b1abe99 100644
--- a/libvlc/jni/libvlcjni-mediaplayer.c
+++ b/libvlc/jni/libvlcjni-mediaplayer.c
@@ -882,25 +882,25 @@ Java_org_videolan_libvlc_MediaPlayer_nativeSetSpuDelay(JNIEnv *env,
}
jboolean
-Java_org_videolan_libvlc_MediaPlayer_nativeSetSubtitleFile(JNIEnv *env,
- jobject thiz,
- jstring jpath)
+Java_org_videolan_libvlc_MediaPlayer_nativeAddSlave(JNIEnv *env,
+ jobject thiz, jint type,
+ jstring jmrl)
{
vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);
- const char* psz_path;
+ const char* psz_mrl;
- if (!jpath || !(psz_path = (*env)->GetStringUTFChars(env, jpath, 0)))
- {
- throw_IllegalArgumentException(env, "path invalid");
+ if (!p_obj)
return false;
- }
- if (!p_obj)
+ if (!jmrl || !(psz_mrl = (*env)->GetStringUTFChars(env, jmrl, 0)))
+ {
+ throw_IllegalArgumentException(env, "mrl invalid");
return false;
+ }
- jboolean ret = libvlc_video_set_subtitle_file(p_obj->u.p_mp, psz_path);
+ jboolean ret = libvlc_media_player_add_slave(p_obj->u.p_mp, type, psz_mrl) == 0;
- (*env)->ReleaseStringUTFChars(env, jpath, psz_path);
+ (*env)->ReleaseStringUTFChars(env, jmrl, psz_mrl);
return ret;
}
diff --git a/libvlc/src/org/videolan/libvlc/Media.java b/libvlc/src/org/videolan/libvlc/Media.java
index c878fb9..ca7200f 100644
--- a/libvlc/src/org/videolan/libvlc/Media.java
+++ b/libvlc/src/org/videolan/libvlc/Media.java
@@ -399,7 +399,7 @@ public class Media extends VLCObject<Media.Event> {
* VLC authorize only "-._~" in Mrl format, android Uri authorize "_-!.~'()*".
* Therefore, encode the characters authorized by Android Uri when creating a mrl from an Uri.
*/
- private static String locationFromUri(Uri uri) {
+ protected static String locationFromUri(Uri uri) {
final char array[] = uri.toString().toCharArray();
final StringBuilder sb = new StringBuilder(array.length * 2);
diff --git a/libvlc/src/org/videolan/libvlc/MediaPlayer.java b/libvlc/src/org/videolan/libvlc/MediaPlayer.java
index ed4bd5b..7c770be 100644
--- a/libvlc/src/org/videolan/libvlc/MediaPlayer.java
+++ b/libvlc/src/org/videolan/libvlc/MediaPlayer.java
@@ -22,6 +22,10 @@
package org.videolan.libvlc;
+import android.net.Uri;
+
+import java.io.File;
+
@SuppressWarnings("unused, JniMissingFunction")
public class MediaPlayer extends VLCObject<MediaPlayer.Event> {
@@ -709,13 +713,25 @@ public class MediaPlayer extends VLCObject<MediaPlayer.Event> {
}
/**
- * Set a new video subtitle file.
+ * Add a slave (or subtitle) to the current media player.
+ *
+ * @param type see {@link org.videolan.libvlc.Media.Slave.Type}
+ * @param uri a valid RFC 2396 Uri
+ * @return true on success.
+ */
+ public boolean addSlave(int type, Uri uri) {
+ return nativeAddSlave(type, Media.locationFromUri(uri));
+ }
+
+ /**
+ * Add a slave (or subtitle) to the current media player.
*
- * @param path local path.
+ * @param type see {@link org.videolan.libvlc.Media.Slave.Type}
+ * @param path a local path
* @return true on success.
*/
- public boolean setSubtitleFile(String path) {
- return nativeSetSubtitleFile(path);
+ public boolean addSlave(int type, String path) {
+ return addSlave(type, Uri.fromFile(new File(path)));
}
/**
@@ -871,6 +887,6 @@ public class MediaPlayer extends VLCObject<MediaPlayer.Event> {
private native boolean nativeSetSpuTrack(int index);
private native long nativeGetSpuDelay();
private native boolean nativeSetSpuDelay(long delay);
- private native boolean nativeSetSubtitleFile(String path);
+ private native boolean nativeAddSlave(int type, String location);
private native boolean nativeSetEqualizer(Equalizer equalizer);
}
diff --git a/libvlc/src/org/videolan/libvlc/media/MediaPlayer.java b/libvlc/src/org/videolan/libvlc/media/MediaPlayer.java
index 4ee499e..af5c509 100644
--- a/libvlc/src/org/videolan/libvlc/media/MediaPlayer.java
+++ b/libvlc/src/org/videolan/libvlc/media/MediaPlayer.java
@@ -35,6 +35,7 @@ import android.view.SurfaceHolder;
import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.Media;
+import java.io.File;
import java.io.FileDescriptor;
import java.io.IOException;
import java.util.Map;
@@ -278,12 +279,12 @@ public class MediaPlayer
public static final String MEDIA_MIMETYPE_TEXT_SUBRIP = "application/x-subrip";
public void addTimedTextSource(String path, String mimeType) {
- mMediaPlayer.setSubtitleFile(path);
+ mMediaPlayer.addSlave(Media.Slave.Type.Subtitle, path);
}
// FIXME: This is incorrect, since libVLC can only add local subtitles
public void addTimedTextSource(Context context, Uri uri, String mimeType) {
- mMediaPlayer.setSubtitleFile(uri.getPath());
+ mMediaPlayer.addSlave(Media.Slave.Type.Subtitle, uri);
}
public void addTimedTextSource(FileDescriptor fd, String mimeType)
diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index b97f067..4a87f58 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -2018,7 +2018,12 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
@MainThread
public boolean addSubtitleTrack(String path) {
- return mMediaPlayer.setSubtitleFile(path);
+ return mMediaPlayer.addSlave(Media.Slave.Type.Subtitle, path);
+ }
+
+ @MainThread
+ public boolean addSubtitleTrack(Uri uri) {
+ return mMediaPlayer.addSlave(Media.Slave.Type.Subtitle, uri);
}
@MainThread
More information about the Android
mailing list