/* * Remove media instance from media list on a position * The {#lock} should be held upon entering this function. * * @param [VLC::Media, Integer] media the media instance or position in array * @return [Boolean] true on success, false if the list is read-only or the item was not found * @todo fixme */ static VALUE rg_remove_media(VALUE self, VALUE media) { int pos; if (TYPE(media) == T_FIXNUM) { pos = NUM2INT(media); /* TODO: G_CHILD_REMOVE */ } else { pos = libvlc_media_list_index_of_item(_SELF(self), RVAL2VLCMEDIA(media)); G_CHILD_REMOVE(self, media); } return ZEROBOOL2RVAL(libvlc_media_list_remove_index(_SELF(self), pos)); }
void VLCWrapper::HandleNextItemSet () { int index = PlayQueue (); if (index < 0) { auto list = List_.get (); index = libvlc_media_list_index_of_item (list, libvlc_media_player_get_media (Player_.get ())); CurrentItemMeta_ = GetItemMeta (index); } emit gotEntity (Util::MakeNotification ("Laure", tr ("%1 - %2").arg (CurrentItemMeta_.Artist_).arg (CurrentItemMeta_.Title_), PInfo_)); CurrentItem_ = index; emit (itemPlayed (CurrentItem_)); }
static void test_media_list (const char ** argv, int argc) { libvlc_instance_t *vlc; libvlc_media_t *md, *md1, *md2, *md3, *md4; libvlc_media_list_t *ml; int ret; log ("Testing media_list\n"); vlc = libvlc_new (argc, argv); assert (vlc != NULL); ml = libvlc_media_list_new (vlc); assert (ml != NULL); md1 = libvlc_media_new_path (vlc, "/dev/null"); assert (md1 != NULL); md2 = libvlc_media_new_path (vlc, "/dev/null"); assert (md2 != NULL); md3 = libvlc_media_new_path (vlc, "/dev/null"); assert (md3 != NULL); ret = libvlc_media_list_add_media (ml, md1); assert (!ret); ret = libvlc_media_list_add_media (ml, md2); assert (!ret); assert( libvlc_media_list_count (ml) == 2 ); assert( libvlc_media_list_index_of_item (ml, md1) == 0 ); assert( libvlc_media_list_index_of_item (ml, md2) == 1 ); ret = libvlc_media_list_remove_index (ml, 0); /* removing first item */ assert (!ret); /* test if second item was moved on first place */ assert( libvlc_media_list_index_of_item (ml, md2) == 0 ); ret = libvlc_media_list_add_media (ml, md1); /* add 2 items */ assert (!ret); ret = libvlc_media_list_add_media (ml, md1); assert (!ret); /* there should be 3 pieces */ assert( libvlc_media_list_count (ml) == 3 ); ret = libvlc_media_list_insert_media (ml, md3, 2); assert (!ret); /* there should be 4 pieces */ assert( libvlc_media_list_count (ml) == 4 ); /* test inserting on right place */ assert( libvlc_media_list_index_of_item (ml, md3) == 2 ); /* test right returning descriptor*/ md = libvlc_media_list_item_at_index (ml, 0); assert(md == md2); libvlc_media_release(md); md = libvlc_media_list_item_at_index (ml, 2); assert(md == md3); libvlc_media_release(md); /* test if give errors, when it should */ /* have 4 items, so index 4 should give error */ ret = libvlc_media_list_remove_index (ml, 4); assert (ret == -1); ret = libvlc_media_list_remove_index (ml, 100); assert (ret == -1); ret = libvlc_media_list_remove_index (ml, -1); assert (ret == -1); /* getting non valid items */ libvlc_media_t * p_non_exist = libvlc_media_list_item_at_index (ml, 4); assert (p_non_exist == NULL); p_non_exist = libvlc_media_list_item_at_index (ml, 100); assert (p_non_exist == NULL); p_non_exist = libvlc_media_list_item_at_index (ml, -1); assert (p_non_exist == NULL); md4 = libvlc_media_new_path (vlc, "/dev/null"); assert (md4 != NULL); /* try to find non inserted item */ int i_non_exist = 0; i_non_exist = libvlc_media_list_index_of_item (ml, md4); assert ( i_non_exist == -1 ); libvlc_media_release (md1); libvlc_media_release (md2); libvlc_media_release (md3); libvlc_media_release (md4); libvlc_media_list_release (ml); libvlc_release (vlc); }
/* * Find index position of List media instance in media list. * Warning: the function will return the first matched position. * The {#lock} should be held upon entering this function. * * @param [VLC::Media] media media instance * @return [Integer] position of media instance or nil if media not found * @todo fixme */ static VALUE rg_index(VALUE self, VALUE media) { int index = libvlc_media_list_index_of_item(_SELF(self), RVAL2VLCMEDIA(media)); return (index < 0) ? Qnil : INT2NUM(index); }