From 794a69356e450a617a4adde3775cfa50ae643a20 Mon Sep 17 00:00:00 2001 From: Filippo Carone Date: Tue, 18 Mar 2008 19:28:38 +0100 Subject: [PATCH] fixes for libvlc medialistplayer_play_item and medialistplayer_play_item_at_index - medialistplayer_play is still out of order --- .../videolan/jvlc/internal/LibVlcState.java | 39 +++++++++++++++++++ .../jvlc/internal/MediaListPlayerTest.java | 39 ++++++++++++++++++- src/control/media_list_player.c | 28 +++++++++++-- 3 files changed, 101 insertions(+), 5 deletions(-) create mode 100644 bindings/java/core/src/main/java/org/videolan/jvlc/internal/LibVlcState.java diff --git a/bindings/java/core/src/main/java/org/videolan/jvlc/internal/LibVlcState.java b/bindings/java/core/src/main/java/org/videolan/jvlc/internal/LibVlcState.java new file mode 100644 index 0000000000..751286187d --- /dev/null +++ b/bindings/java/core/src/main/java/org/videolan/jvlc/internal/LibVlcState.java @@ -0,0 +1,39 @@ +/***************************************************************************** + * LibVlcState.java: VLC Java Bindings + ***************************************************************************** + * Copyright (C) 1998-2008 the VideoLAN team + * + * Authors: Filippo Carone + * + * + * $Id $ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + *****************************************************************************/ + +package org.videolan.jvlc.internal; + + +public enum LibVlcState +{ + libvlc_NothingSpecial, + libvlc_Stopped, + libvlc_Opening, + libvlc_Buffering, + libvlc_Ended, + libvlc_Error, + libvlc_Playing, + libvlc_Paused +} diff --git a/bindings/java/core/src/test/java/org/videolan/jvlc/internal/MediaListPlayerTest.java b/bindings/java/core/src/test/java/org/videolan/jvlc/internal/MediaListPlayerTest.java index f6e436a8ab..c8ec022a8e 100644 --- a/bindings/java/core/src/test/java/org/videolan/jvlc/internal/MediaListPlayerTest.java +++ b/bindings/java/core/src/test/java/org/videolan/jvlc/internal/MediaListPlayerTest.java @@ -110,10 +110,10 @@ public class MediaListPlayerTest Assert.assertEquals(1, exception.raised); } -// @Test /** - * disabled: see https://trac.videolan.org/vlc/attachment/ticket/1527 + * this fails: see https://trac.videolan.org/vlc/attachment/ticket/1527 */ + @Test public void mediaListPlayerPlay() { libvlc_exception_t exception = new libvlc_exception_t(); @@ -123,6 +123,41 @@ public class MediaListPlayerTest libvlc.libvlc_media_list_add_media_descriptor(mediaList, mediaDescriptor, exception); libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception); libvlc.libvlc_media_list_player_play(mediaListPlayer, exception); + Assert.assertEquals("Exception message: " + exception.message + ".\n", 0, exception.raised); + } + + @Test + public void mediaListPlayerPlayItemAtIndex() + { + libvlc_exception_t exception = new libvlc_exception_t(); + LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception); + LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception); + LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_descriptor_new(libvlcInstance, mrl, exception); + libvlc.libvlc_media_list_add_media_descriptor(mediaList, mediaDescriptor, exception); + libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception); + libvlc.libvlc_media_list_player_play_item_at_index(mediaListPlayer, 0, exception); + } + + @Test + public void mediaListPlayerPlayItem() throws Exception + { + libvlc_exception_t exception = new libvlc_exception_t(); + LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception); + LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception); + LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_descriptor_new(libvlcInstance, mrl, exception); + libvlc.libvlc_media_list_add_media_descriptor(mediaList, mediaDescriptor, exception); + libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception); + libvlc.libvlc_media_list_player_play_item(mediaListPlayer, mediaDescriptor, exception); + Thread.sleep(6000); + } + + @Test + public void mediaListPlayerGetStateStopped() + { + libvlc_exception_t exception = new libvlc_exception_t(); + LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception); + int state = libvlc.libvlc_media_list_player_get_state(mediaListPlayer, exception); + Assert.assertEquals(LibVlcState.libvlc_Stopped.ordinal(), state); } } diff --git a/src/control/media_list_player.c b/src/control/media_list_player.c index a1239f8c29..ee139cdec9 100644 --- a/src/control/media_list_player.c +++ b/src/control/media_list_player.c @@ -41,6 +41,11 @@ get_next_path( libvlc_media_list_player_t * p_mlp ) libvlc_media_list_t * p_parent_of_playing_item; libvlc_media_list_t * p_sublist_of_playing_item; + if ( !p_mlp->current_playing_item_path ) + { + p_mlp->current_playing_item_path = libvlc_media_list_path_empty(); + } + p_sublist_of_playing_item = libvlc_media_list_sublist_at_path( p_mlp->p_mlist, p_mlp->current_playing_item_path ); @@ -149,6 +154,11 @@ install_playlist_observer( libvlc_media_list_player_t * p_mlp ) static void uninstall_playlist_observer( libvlc_media_list_player_t * p_mlp ) { + if ( !p_mlp->p_mlist ) + { + return; + } + libvlc_event_detach( libvlc_media_list_event_manager( p_mlp->p_mlist, NULL ), libvlc_MediaListItemDeleted, mlist_item_deleted, p_mlp, NULL ); } @@ -171,6 +181,11 @@ install_media_instance_observer( libvlc_media_list_player_t * p_mlp ) static void uninstall_media_instance_observer( libvlc_media_list_player_t * p_mlp ) { + if ( !p_mlp->p_mi ) + { + return; + } + libvlc_event_detach( libvlc_media_instance_event_manager( p_mlp->p_mi, NULL ), libvlc_MediaInstanceReachedEnd, media_instance_reached_end, p_mlp, NULL ); @@ -204,6 +219,12 @@ set_current_playing_item( libvlc_media_list_player_t * p_mlp, /* We are not interested in getting media_descriptor stop event now */ uninstall_media_instance_observer( p_mlp ); + + if ( !p_mlp->p_mi ) + { + p_mlp->p_mi = libvlc_media_instance_new_from_media_descriptor(p_md, p_e); + } + if( p_md->p_subitems && libvlc_media_list_count( p_md->p_subitems, NULL ) > 0 ) { libvlc_media_descriptor_t * p_submd; @@ -218,8 +239,6 @@ set_current_playing_item( libvlc_media_list_player_t * p_mlp, vlc_mutex_unlock( &p_mlp->object_lock ); - libvlc_media_list_unlock( p_mlp->p_mlist ); - libvlc_media_descriptor_release( p_md ); /* for libvlc_media_list_item_at_index */ } @@ -413,7 +432,10 @@ void libvlc_media_list_player_play_item( void libvlc_media_list_player_stop( libvlc_media_list_player_t * p_mlp, libvlc_exception_t * p_e ) { - libvlc_media_instance_stop( p_mlp->p_mi, p_e ); + if ( p_mlp->p_mi ) + { + libvlc_media_instance_stop( p_mlp->p_mi, p_e ); + } vlc_mutex_lock( &p_mlp->object_lock ); free( p_mlp->current_playing_item_path ); -- 2.39.2