void Java_org_videolan_libvlc_MediaList_loadPlaylist(JNIEnv *env, jobject thiz, jobject libvlcJava, jstring mrl, jobject items) { const char* p_mrl = (*env)->GetStringUTFChars(env, mrl, NULL); libvlc_media_t *p_md = libvlc_media_new_location((libvlc_instance_t*)(intptr_t)getLong(env, libvlcJava, "mLibVlcInstance"), p_mrl); libvlc_media_add_option(p_md, ":demux=playlist,none"); libvlc_media_add_option(p_md, ":run-time=1"); struct stopped_monitor* monitor = malloc(sizeof(struct stopped_monitor)); pthread_mutex_init(&monitor->doneMutex, NULL); pthread_cond_init(&monitor->doneCondVar, NULL); monitor->stopped = false; pthread_mutex_lock(&monitor->doneMutex); libvlc_media_player_t* p_mp = libvlc_media_player_new((libvlc_instance_t*)(intptr_t)getLong(env, libvlcJava, "mLibVlcInstance")); libvlc_media_player_set_video_title_display(p_mp, libvlc_position_disable, 0); libvlc_event_manager_t* ev = libvlc_media_player_event_manager(p_mp); libvlc_event_attach(ev, libvlc_MediaPlayerEndReached, stopped_callback, monitor); libvlc_media_player_set_media(p_mp, p_md); libvlc_media_player_play(p_mp); struct timespec deadline; clock_gettime(CLOCK_REALTIME, &deadline); deadline.tv_sec += 2; /* If "VLC can't open the file", return */ int mp_alive = 1; while(!(monitor->stopped) && mp_alive) { pthread_cond_timedwait(&monitor->doneCondVar, &monitor->doneMutex, &deadline); mp_alive = libvlc_media_player_will_play(p_mp); } pthread_mutex_unlock(&monitor->doneMutex); pthread_mutex_destroy(&monitor->doneMutex); pthread_cond_destroy(&monitor->doneCondVar); free(monitor); libvlc_media_player_release(p_mp); expand_media_internal(env, (libvlc_instance_t*)(intptr_t)getLong(env, libvlcJava, "mLibVlcInstance"), items, p_md); (*env)->ReleaseStringUTFChars(env, mrl, p_mrl); }
jboolean Java_org_videolan_libvlc_LibVLC_hasVideoTrack(JNIEnv *env, jobject thiz, jlong i_instance, jstring fileLocation) { /* Create a new item and assign it to the media player. */ libvlc_media_t *p_m = new_media(i_instance, env, thiz, fileLocation, false, false); if (p_m == NULL) { LOGE("Could not create the media!"); return JNI_FALSE; } /* Get the tracks information of the media. */ libvlc_media_parse(p_m); libvlc_media_player_t* p_mp = libvlc_media_player_new_from_media(p_m); libvlc_media_player_set_video_title_display(p_mp, libvlc_position_disable, 0); struct length_change_monitor* monitor; monitor = malloc(sizeof(struct length_change_monitor)); if (!monitor) return 0; /* Initialize pthread variables. */ pthread_mutex_init(&monitor->doneMutex, NULL); pthread_cond_init(&monitor->doneCondVar, NULL); monitor->length_changed = false; libvlc_event_manager_t *ev = libvlc_media_player_event_manager(p_mp); libvlc_event_attach(ev, libvlc_MediaPlayerLengthChanged, length_changed_callback, monitor); libvlc_media_player_play( p_mp ); pthread_mutex_lock(&monitor->doneMutex); struct timespec deadline; clock_gettime(CLOCK_REALTIME, &deadline); deadline.tv_sec += 2; /* If "VLC can't open the file", return */ int mp_alive = 1; while( !monitor->length_changed && mp_alive ) { pthread_cond_timedwait(&monitor->doneCondVar, &monitor->doneMutex, &deadline); mp_alive = libvlc_media_player_will_play(p_mp); } pthread_mutex_unlock(&monitor->doneMutex); int i_nbTracks; if( mp_alive ) i_nbTracks = libvlc_video_get_track_count(p_mp); else i_nbTracks = -1; LOGI("Number of video tracks: %d",i_nbTracks); libvlc_event_detach(ev, libvlc_MediaPlayerLengthChanged, length_changed_callback, monitor); libvlc_media_player_stop(p_mp); libvlc_media_player_release(p_mp); libvlc_media_release(p_m); pthread_mutex_destroy(&monitor->doneMutex); pthread_cond_destroy(&monitor->doneCondVar); free(monitor); if(i_nbTracks > 0) return JNI_TRUE; else if(i_nbTracks < 0) (*env)->ThrowNew(env, (*env)->FindClass(env, "java/io/IOException"), "VLC can't open the file"); else return JNI_FALSE; }
int libvlc_status(int nameId) { CHECK_NAMEID(nameId); return libvlc_media_player_will_play(soundPlay[nameId]); }
bool can_play() { if(mediaplay != NULL) return libvlc_media_player_will_play(mediaplay); return false; }