Commit 03220852 authored by Thomas Guillem's avatar Thomas Guillem

LibVLC: replace setSubtitleFile with addSlave

parent 1cb97a47
......@@ -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;
}
......
......@@ -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);
......
......@@ -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);
}
......@@ -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)
......
......@@ -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
......
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