我想在android vlc应用程序中订阅MediaPlayer缓冲事件。
我编辑了EventHandler类并取消注释了事件常量。
public static final int MediaPlayerBuffering = 0x103; // ** uncommented this**
public static final int MediaPlayerPlaying = 0x104;
然后我在libvlcjni.c中添加了变量
libvlc_event_manager_t *ev = libvlc_media_player_event_manager(mp);
static const libvlc_event_type_t mp_events[] = {
libvlc_MediaPlayerPlaying,
libvlc_MediaPlayerPaused,
libvlc_MediaPlayerEndReached,
libvlc_MediaPlayerStopped,
libvlc_MediaPlayerVout,
libvlc_MediaPlayerPositionChanged,
libvlc_MediaPlayerEncounteredError,
libvlc_MediaPlayerBuffering // **added this here**
};
重新编译jni以获取so文件,然后构建vlc应用程序,但事件似乎永远不会发生。
由于缺少带宽,当我遇到缓冲事件时,还需要链接以获取事件。
我可以在logcat中看到它在6ms内打印1001 ms缓冲区。但这来自较低层而不是java层
答案 0 :(得分:4)
必须在libvlcjni.c文件中添加它
else if(ev->type == libvlc_MediaPlayeBuffering) {
/* For determining the vout/ES track change */
jstring sData = (*env)->NewStringUTF(env, "data");
(*env)->CallVoidMethod(env, bundle, putFloat, sData, ev->u.media_player_buffer.new_cache);
(*env)->DeleteLocalRef(env, sData);
}
希望这有助于某人
答案 1 :(得分:2)
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);
}
答案是ev-> u.media_player_buffering.new_cache
在VLC文件mediaPlayer.c中 我找到了这段代码:
`else if( newval.i_int == INPUT_EVENT_CACHE )
{
event.type = libvlc_MediaPlayerBuffering;
event.u.media_player_buffering.new_cache = (int)(100 * var_GetFloat( p_input, "cache" ));
libvlc_event_send( p_mi->p_event_manager, &event );
}
`
和libvlc_events.h
/* media instance */
struct
{
float new_cache;
} media_player_buffering;
然后,我编译了它并且它起作用了。特别感谢我的男孩Tracy在海岸!