vlc-android的编译,就不累赘了,网上有很多资源,我参考的是https://blog.csdn.net/wkw1125/article/details/56845405.
首先我们需要加入录像和截图功能的补丁https://patches.videolan.org/patch/606/,下载下来放在vlc里面,使用命令patch -p1 < xxxx.patch打上补丁,可能有些地方会失败,根据终端的提示,手动把失败的补丁加进去.由于vlc一直在更新,所以补丁里一些方法可能与版本有差异,编译会不通过,根据编译的报错查找相应的代码去修改即可.
接着在libvlcjni-mediaplayer.c中加入以下代码:
jboolean Java_org_videolan_libvlc_MediaPlayer_takeSnapShot(JNIEnv *env, jobject thiz,jint number, jstring path, jint width,jint height)
{
jboolean isCopy;
/*libvlc_media_player_t *mp = getMediaPlayer(env, thiz); */
vlcjni_object *p_obj = VLCJniObject_getInstance(env,thiz);
libvlc_media_player_t *mp = p_obj->u.p_mp;
/* Get C string */
const char* psz_path = (*env)->GetStringUTFChars(env, path, &isCopy);
if (mp)
if(libvlc_video_take_snapshot(mp, (int)number,psz_path , (int)width,(int)height)==0)
return JNI_TRUE;
return JNI_FALSE;
}
jboolean Java_org_videolan_libvlc_MediaPlayer_videoRecordStart(JNIEnv *env, jobject thiz,jstring psz_filpath,jstring psz_filename)
{
jboolean isCopy;
/*libvlc_media_player_t *mp = getMediaPlayer(env, thiz); */
vlcjni_object *p_obj = VLCJniObject_getInstance(env,thiz);
libvlc_media_player_t *mp = p_obj->u.p_mp;
/* Get C string */
const char* psz_path = (*env)->GetStringUTFChars(env, psz_filpath, &isCopy);
const char* psz_name=(*env)->GetStringUTFChars(env, psz_filename, &isCopy);
if (mp)
if(libvlc_media_player_record_start(mp,psz_path,psz_name)==0)
return JNI_TRUE;
return JNI_FALSE;
}
jboolean Java_org_videolan_libvlc_MediaPlayer_videoRecordStop(JNIEnv *env, jobject thiz)
{
jboolean isCopy;
/*libvlc_media_player_t *mp = getMediaPlayer(env, thiz); */
vlcjni_object *p_obj = VLCJniObject_getInstance(env,thiz);
libvlc_media_player_t *mp = p_obj->u.p_mp;
/* Get C string */
if (mp)
if(libvlc_media_player_record_stop(mp)==0)
return JNI_TRUE;
return JNI_FALSE;
}
jboolean Java_org_videolan_libvlc_MediaPlayer_videoIsRecording(JNIEnv *env, jobject thiz)
{
jboolean isCopy;
vlcjni_object *p_obj = VLCJniObject_getInstance(env,thiz);
libvlc_media_player_t *mp = p_obj->u.p_mp;
if (mp)
if(libvlc_media_player_is_recording(mp))
return JNI_TRUE;
return JNI_FALSE;
}
jboolean Java_org_videolan_libvlc_MediaPlayer_videoIsRecordable(JNIEnv *env, jobject thiz)
{
jboolean isCopy;
/*libvlc_media_player_t *mp = getMediaPlayer(env, thiz);*/
vlcjni_object *p_obj = VLCJniObject_getInstance(env,thiz);
libvlc_media_player_t *mp = p_obj->u.p_mp;
if (mp)
if(libvlc_media_player_is_recordable(mp))
return JNI_TRUE;
return JNI_FALSE;
}
jint Java_org_videolan_libvlc_MediaPlayer_getState(JNIEnv *env, jobject thiz)
{
/*libvlc_media_player_t *mp = getMediaPlayer(env, thiz);*/
vlcjni_object *p_obj = VLCJniObject_getInstance(env,thiz);
libvlc_media_player_t *mp = p_obj->u.p_mp;
if (mp){
libvlc_state_t state=libvlc_media_player_get_state(mp);
return (jint)state;
}
else
return -1;
}其中的getMediaPlayer换成VLCJniObject_getINstance.
接着在java层Mediaplayer中添加相应的native方法并调用即可.