主页 > 原创 | 整理 | 学习笔记 > libvlc-android编译及启用网络流缓冲事件

libvlc-android编译及启用网络流缓冲事件

libvlc是一个很强大的视频播放库,在android调用可以直接播放rtmp视频流,我写这篇用来记录libvlc对android的编译过程及如何打开网络流缓冲事件。

打开/添加缓冲事件
打开缓冲事件主要需要修改libvlc/jni/libvlcjni.c文件及libvlc/src/org/videolan/libvlc/EventHandler.java文件,diff代码如下:

diff --git a/libvlc/jni/libvlcjni.c b/libvlc/jni/libvlcjni.c
index 083162b..12eba41 100644
--- a/libvlc/jni/libvlcjni.c
+++ b/libvlc/jni/libvlcjni.c
@@ -190,6 +190,11 @@ static void vlc_event_callback(const libvlc_event_t *ev, void *data)
         (*env)->DeleteLocalRef(env, item_uri_value);
         (*env)->DeleteLocalRef(env, item_index);
         free(mrl);
+    } else if(ev->type == libvlc_MediaPlayerBuffering) {
+        /* For determining the vout/ES track change */
+        jstring sData = (*env)->NewStringUTF(env, "data");
+        (*env)->CallVoidMethod(env, bundle, putFloat, sData, ev->u.media_player_buffering.new_cache);
+        (*env)->DeleteLocalRef(env, sData);
     }
 
     /* Get the object class */
@@ -551,7 +556,8 @@ void Java_org_videolan_libvlc_LibVLC_playMRL(JNIEnv *env, jobject thiz,
         libvlc_MediaPlayerVout,
         libvlc_MediaPlayerPositionChanged,
         libvlc_MediaPlayerTimeChanged,
-        libvlc_MediaPlayerEncounteredError
+        libvlc_MediaPlayerEncounteredError,
+        libvlc_MediaPlayerBuffering
     };
     for(int i = 0; i < (sizeof(mp_events) / sizeof(*mp_events)); i++)
         libvlc_event_attach(ev, mp_events[i], vlc_event_callback, myVm);
diff --git a/libvlc/src/org/videolan/libvlc/EventHandler.java b/libvlc/src/org/videolan/libvlc/EventHandler.java
index 6242b2d..4d787fc 100644
--- a/libvlc/src/org/videolan/libvlc/EventHandler.java
+++ b/libvlc/src/org/videolan/libvlc/EventHandler.java
@@ -42,7 +42,7 @@ public class EventHandler {
     //public static final int MediaPlayerMediaChanged         = 0x100;
     //public static final int MediaPlayerNothingSpecial       = 0x101;
     //public static final int MediaPlayerOpening              = 0x102;
-    //public static final int MediaPlayerBuffering            = 0x103;
+    public static final int MediaPlayerBuffering            = 0x103;
     public static final int MediaPlayerPlaying                = 0x104;
     public static final int MediaPlayerPaused                 = 0x105;
     public static final int MediaPlayerStopped                = 0x106;

编译过程可以参考官方文档
https://wiki.videolan.org/AndroidCompile

编译环境为ubuntu14.04 64位,已安装好android sdk及ndk。流程如下:
1.环境变量写入到~/.bashrc里

export ANDROID_SDK=/path/to/android-sdk
export ANDROID_NDK=/path/to/android-ndk
export PATH=$PATH:$ANDROID_SDK/platform-tools:$ANDROID_SDK/tools

修改其中sdk及ndk为你自己的目录最后不要忘记在当前终端下运行

source ~/.bashrc

2.下载代码

git clone git://git.videolan.org/vlc-ports/android.git

3.编译

sh compile.sh -a armeabi-v7a

4.编译release版本

export ANDROID_ABI=armeabi-v7a
sh compile.sh release

生成文件在./libvlc/jni/libs/armeabi-v7a/

Tags: android libvlc libvlc-android ubuntu vlc vlc缓冲

发表评论

电子邮件地址不会被公开。 必填项已用*标注