[Android] LibVLC: MediaPlayer: add Set/Get AspectRatio methods

Thomas Guillem git at videolan.org
Mon Nov 28 16:39:11 CET 2016


vlc-android | branch: master | Thomas Guillem <thomas at gllm.fr> | Thu Nov 24 10:59:08 2016 +0100| [3873d60324183509b0691a54c543be8c9c8b6eb0] | committer: Thomas Guillem

LibVLC: MediaPlayer: add Set/Get AspectRatio methods

> https://code.videolan.org/videolan/vlc-android/commit/3873d60324183509b0691a54c543be8c9c8b6eb0
---

 libvlc/jni/libvlcjni-mediaplayer.c              | 42 ++++++++++++++++++++++++-
 libvlc/src/org/videolan/libvlc/MediaPlayer.java | 20 ++++++++++++
 2 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/libvlc/jni/libvlcjni-mediaplayer.c b/libvlc/jni/libvlcjni-mediaplayer.c
index f63d242..e36d26b 100644
--- a/libvlc/jni/libvlcjni-mediaplayer.c
+++ b/libvlc/jni/libvlcjni-mediaplayer.c
@@ -904,6 +904,47 @@ Java_org_videolan_libvlc_MediaPlayer_nativeSetScale(JNIEnv *env, jobject thiz,
     libvlc_video_set_scale(p_obj->u.p_mp, factor);
 }
 
+jstring
+Java_org_videolan_libvlc_MediaPlayer_nativeGetAspectRatio(JNIEnv *env,
+                                                          jobject thiz)
+{
+    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);
+
+    if (!p_obj)
+        return NULL;
+
+    char *psz_aspect = libvlc_video_get_aspect_ratio(p_obj->u.p_mp);
+    jstring jaspect = psz_aspect ? (*env)->NewStringUTF(env, psz_aspect) : NULL;
+    free(psz_aspect);
+    return jaspect;
+}
+
+void
+Java_org_videolan_libvlc_MediaPlayer_nativeSetAspectRatio(JNIEnv *env,
+                                                          jobject thiz,
+                                                          jstring jaspect)
+{
+    const char* psz_aspect;
+    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);
+
+    if (!p_obj)
+        return;
+
+    if (!jaspect)
+    {
+        libvlc_video_set_aspect_ratio(p_obj->u.p_mp, NULL);
+        return;
+    }
+    if (!(psz_aspect = (*env)->GetStringUTFChars(env, jaspect, 0)))
+    {
+        throw_IllegalArgumentException(env, "aspect invalid");
+        return;
+    }
+
+    libvlc_video_set_aspect_ratio(p_obj->u.p_mp, psz_aspect);
+    (*env)->ReleaseStringUTFChars(env, jaspect, psz_aspect);
+}
+
 jboolean
 Java_org_videolan_libvlc_MediaPlayer_nativeAddSlave(JNIEnv *env,
                                                     jobject thiz, jint type,
@@ -971,7 +1012,6 @@ Java_org_videolan_libvlc_MediaPlayer_00024Equalizer_nativeGetPresetName(JNIEnv *
     psz_name = libvlc_audio_equalizer_get_preset_name(index);
 
     return psz_name ? (*env)->NewStringUTF(env, psz_name) : NULL;
-
 }
 
 jint
diff --git a/libvlc/src/org/videolan/libvlc/MediaPlayer.java b/libvlc/src/org/videolan/libvlc/MediaPlayer.java
index 676a92e..ed26fb5 100644
--- a/libvlc/src/org/videolan/libvlc/MediaPlayer.java
+++ b/libvlc/src/org/videolan/libvlc/MediaPlayer.java
@@ -499,6 +499,24 @@ public class MediaPlayer extends VLCObject<MediaPlayer.Event> {
     }
 
     /**
+     * Get current video aspect ratio
+     *
+     * @return the video aspect ratio or NULL if unspecified
+     */
+    public String getAspectRatio() {
+        return nativeGetAspectRatio();
+    }
+
+    /**
+     * Set new video aspect ratio.
+     *
+     * @param aspect new video aspect-ratio or NULL to reset to default
+     */
+    public void setAspectRatio(String aspect) {
+        nativeSetAspectRatio(aspect);
+    }
+
+    /**
      * Selects an audio output module.
      * Any change will take effect only after playback is stopped and
      * restarted. Audio output cannot be changed while playing.
@@ -899,6 +917,8 @@ public class MediaPlayer extends VLCObject<MediaPlayer.Event> {
     private native void nativeSetVideoTitleDisplay(int position, int timeout);
     private native float nativeGetScale();
     private native void nativeSetScale(float scale);
+    private native String nativeGetAspectRatio();
+    private native void nativeSetAspectRatio(String aspect);
     private native boolean nativeSetAudioOutput(String aout);
     private native boolean nativeSetAudioOutputDevice(String id);
     private native Title[] nativeGetTitles();



More information about the Android mailing list