⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 media_list_player.c

📁 VLC Player Source Code
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************** * media_list_player.c: libvlc new API media_list player functions ***************************************************************************** * Copyright (C) 2007 the VideoLAN team * $Id$ * * Authors: Pierre d'Herbemont <pdherbemont # videolan.org> * * 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/#include "libvlc_internal.h"#include <vlc/libvlc.h>#include "media_list_path.h"/* * Private functions *//************************************************************************** *       get_next_index (private) * * Simple next item fetcher. **************************************************************************/static libvlc_media_list_path_tget_next_path( libvlc_media_list_player_t * p_mlp ){    /* We are entered with libvlc_media_list_lock( p_mlp->p_list ) */    libvlc_media_list_path_t ret;    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 )    {        if( !libvlc_media_list_count( p_mlp->p_mlist, NULL ) )            return NULL;        return libvlc_media_list_path_with_root_index(0);    }        p_sublist_of_playing_item = libvlc_media_list_sublist_at_path(                            p_mlp->p_mlist,                            p_mlp->current_playing_item_path );     /* If item just gained a sublist just play it */    if( p_sublist_of_playing_item )    {        libvlc_media_list_release( p_sublist_of_playing_item );        return libvlc_media_list_path_copy_by_appending( p_mlp->current_playing_item_path, 0 );    }    /* Try to catch next element */    p_parent_of_playing_item = libvlc_media_list_parentlist_at_path(                            p_mlp->p_mlist,                            p_mlp->current_playing_item_path );    int deepness = libvlc_media_list_path_deepness( p_mlp->current_playing_item_path );    if( deepness < 1 || !p_parent_of_playing_item )        return NULL;    ret = libvlc_media_list_path_copy( p_mlp->current_playing_item_path );    while( ret[deepness-1] >= libvlc_media_list_count( p_parent_of_playing_item, NULL ) )    {        deepness--;        if( deepness <= 0 )        {            free( ret );            libvlc_media_list_release( p_parent_of_playing_item );            return NULL;        }        ret[deepness] = -1;        ret[deepness-1]++;        p_parent_of_playing_item  = libvlc_media_list_parentlist_at_path(                                        p_mlp->p_mlist,                                        ret );    }    libvlc_media_list_release( p_parent_of_playing_item );    return ret;}/************************************************************************** *       media_player_reached_end (private) (Event Callback) **************************************************************************/static voidmedia_player_reached_end( const libvlc_event_t * p_event,                            void * p_user_data ){    libvlc_media_list_player_t * p_mlp = p_user_data;    libvlc_media_player_t * p_mi = p_event->p_obj;    libvlc_media_t *p_md, * p_current_md;    p_md = libvlc_media_player_get_media( p_mi, NULL );    /* XXX: need if p_mlp->p_current_playing_index is beyond */    p_current_md = libvlc_media_list_item_at_path(                        p_mlp->p_mlist,                        p_mlp->current_playing_item_path );    if( p_md != p_current_md )    {        msg_Warn( p_mlp->p_libvlc_instance->p_libvlc_int,                  "We are not sync-ed with the media instance" );        libvlc_media_release( p_md );        libvlc_media_release( p_current_md );        return;    }    libvlc_media_release( p_md );    libvlc_media_release( p_current_md );    libvlc_media_list_player_next( p_mlp, NULL );}/************************************************************************** *       playlist_item_deleted (private) (Event Callback) **************************************************************************/static voidmlist_item_deleted( const libvlc_event_t * p_event, void * p_user_data ){    libvlc_media_t * p_current_md;    libvlc_media_list_player_t * p_mlp = p_user_data;    libvlc_media_list_t * p_emitting_mlist = p_event->p_obj;    /* XXX: need if p_mlp->p_current_playing_index is beyond */    p_current_md = libvlc_media_list_item_at_path(                        p_mlp->p_mlist,                        p_mlp->current_playing_item_path );    if( p_event->u.media_list_item_deleted.item == p_current_md &&        p_emitting_mlist == p_mlp->p_mlist )    {        /* We are playing this item, we choose to stop */        libvlc_media_list_player_stop( p_mlp, NULL );    }}/************************************************************************** *       install_playlist_observer (private) **************************************************************************/static voidinstall_playlist_observer( libvlc_media_list_player_t * p_mlp ){    libvlc_event_attach( libvlc_media_list_event_manager( p_mlp->p_mlist, NULL ),            libvlc_MediaListItemDeleted, mlist_item_deleted, p_mlp, NULL );}/************************************************************************** *       uninstall_playlist_observer (private) **************************************************************************/static voiduninstall_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 );}/************************************************************************** *       install_media_player_observer (private) **************************************************************************/static voidinstall_media_player_observer( libvlc_media_list_player_t * p_mlp ){    libvlc_event_attach( libvlc_media_player_event_manager( p_mlp->p_mi, NULL ),                         libvlc_MediaPlayerEndReached,                          media_player_reached_end, p_mlp, NULL );}/************************************************************************** *       uninstall_media_player_observer (private) **************************************************************************/static voiduninstall_media_player_observer( libvlc_media_list_player_t * p_mlp ){    if ( !p_mlp->p_mi )    {        return;    }    libvlc_event_detach( libvlc_media_player_event_manager( p_mlp->p_mi, NULL ),                         libvlc_MediaPlayerEndReached,                         media_player_reached_end, p_mlp, NULL );}/************************************************************************** *       set_current_playing_item (private) * * Playlist lock should be held **************************************************************************/static voidset_current_playing_item( libvlc_media_list_player_t * p_mlp,                          libvlc_media_list_path_t path,                          libvlc_exception_t * p_e ){    VLC_UNUSED(p_e);    libvlc_media_t * p_md;    p_md = libvlc_media_list_item_at_path( p_mlp->p_mlist, path );    vlc_mutex_lock( &p_mlp->object_lock );    if( p_mlp->current_playing_item_path != path )    {        free( p_mlp->current_playing_item_path );        p_mlp->current_playing_item_path = path;    }    if( !p_md )    {        vlc_mutex_unlock( &p_mlp->object_lock );        return;    }    /* We are not interested in getting media stop event now */    uninstall_media_player_observer( p_mlp );    if ( !p_mlp->p_mi )    {        p_mlp->p_mi = libvlc_media_player_new_from_media(p_md, p_e);    }        if( p_md->p_subitems && libvlc_media_list_count( p_md->p_subitems, NULL ) > 0 )    {        libvlc_media_t * p_submd;        p_submd = libvlc_media_list_item_at_index( p_md->p_subitems, 0, NULL );        libvlc_media_player_set_media( p_mlp->p_mi, p_submd, NULL );        libvlc_media_release( p_submd );    }    else        libvlc_media_player_set_media( p_mlp->p_mi, p_md, NULL );//    wait_playing_state(); /* If we want to be synchronous */    install_media_player_observer( p_mlp );    vlc_mutex_unlock( &p_mlp->object_lock );    libvlc_media_release( p_md ); /* for libvlc_media_list_item_at_index */}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -