分类: Android平台
2013-07-10 17:39:36
int libvlc_NothingSpecial=0; int libvlc_Opening=1; int libvlc_Buffering=2; int libvlc_Playing=3; int libvlc_Paused=4; int libvlc_Stopped=5; int libvlc_Ended=6; int libvlc_Error=7;vlc_android 中的LibVLC.java没有取得这些状态的接口,只有一个
/** * Returns true if any media is playing */ public native boolean isPlaying();
可什么是is playing呢?在vlc 源码中,能看到
(state == libvlc_Opening) || (state == libvlc_Buffering) || (state == libvlc_Playing)这三个状态是isPlaying。
有时候我们的需求更细致,如果要在网络视频播放之前加上一个ProgressBar,视频开始播放就取消ProgressBar,这时就必须知道libvlc_Playing何时出现。
为了获得更细分的状态,只有自己修改libvlcjni.c了,在该文件最后加上
jint Java_org_videolan_vlc_LibVLC_getState(JNIEnv *env, jobject thiz) { libvlc_media_list_player_t *mp = getMediaListPlayer(env, thiz); if (mp){ libvlc_state_t state=libvlc_media_list_player_get_state(mp); return (jint)state; } else return -1; }在LibVLC.java中增加native函数:
public native int getState();编译vlc android源码,就能得到libvlcjni.so了,加入你的项目中即可。
例子如下,
load(url); loadingDialog = ProgressDialog.show(this, "", "加载中,请稍等 …", false, true); new Thread(new Runnable() { @Override public void run() { while (true) { try { Thread.sleep(1000); Log.d(TAG,"progress dialog():"+mLibVLC.getState()); if(mLibVLC != null &&mLibVLC.getState()==LibVLC_State.libvlc_Playing){ loadingDialog.dismiss(); break; } } catch (InterruptedException e) { e.printStackTrace(); } } } }).start();