MediaListPlayer.hpp 5.29 KB
Newer Older
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
1 2 3 4 5 6
/*****************************************************************************
 * libvlc_MediaListPlayer.hpp: MediaListPlayer API
 *****************************************************************************
 * Copyright © 2014 the VideoLAN team
 *
 * Authors: Alexey Sokolov <alexey@alexeysokolov.co.cc>
7
 *          Hugo Beauzée-Luyssen <hugo@beauzee.fr>
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser 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.
 *****************************************************************************/

#ifndef LIBVLC_CXX_MEDIALISTPLAYER_H
#define LIBVLC_CXX_MEDIALISTPLAYER_H

27 28
#include <string>

29
#include "common.hpp"
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
30

31
namespace VLC
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
32 33
{

34
class MediaListPlayerEventManager;
35 36
class MediaPlayer;
class MediaList;
37

38
class MediaListPlayer : public Internal<libvlc_media_list_player_t>
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
39 40 41 42 43 44 45
{
public:
    /**
     * Check if 2 MediaListPlayer objects contain the same libvlc_media_list_player_t.
     * \param another another MediaListPlayer
     * \return true if they contain the same libvlc_media_list_player_t
     */
46 47 48 49
    bool operator==(const MediaListPlayer& another) const
    {
        return m_obj == another.m_obj;
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
50 51 52 53 54 55

    /**
     * Create new media_list_player.
     *
     * \param p_instance  libvlc instance
     */
56 57 58
    MediaListPlayer(Instance& instance)
        : Internal{ libvlc_media_list_player_new( getInternalPtr<libvlc_instance_t>( instance ) ),
                    libvlc_media_list_player_release }
59 60 61
    {
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
62 63 64 65 66 67

    /**
     * Return the event manager of this media_list_player.
     *
     * \return the event manager
     */
68
    MediaListPlayerEventManager& eventManager()
69 70 71
    {
        if ( m_eventManager )
        {
72
            libvlc_event_manager_t* obj = libvlc_media_list_player_event_manager(*this);
73
            m_eventManager = std::make_shared<MediaListPlayerEventManager>( obj );
74
        }
75
        return *m_eventManager;
76 77
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
78 79 80 81 82 83

    /**
     * Replace media player in media_list_player with this instance.
     *
     * \param p_mi  media player instance
     */
84
    void setMediaPlayer(const MediaPlayer& mi)
85
    {
86
        libvlc_media_list_player_set_media_player( *this,
87 88
                        getInternalPtr<libvlc_media_player_t>( mi ) );
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
89 90 91 92 93 94

    /**
     * Set the media list associated with the player
     *
     * \param p_mlist  list of media
     */
95
    void setMediaList(const MediaList& mlist)
96
    {
97
        libvlc_media_list_player_set_media_list( *this,
98 99
                            getInternalPtr<libvlc_media_list_t>( mlist ) );
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
100 101 102 103

    /**
     * Play media list
     */
104 105
    void play()
    {
106
        libvlc_media_list_player_play(*this);
107
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
108 109 110 111

    /**
     * Toggle pause (or resume) media list
     */
112 113
    void pause()
    {
114
        libvlc_media_list_player_pause(*this);
115
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
116 117 118 119 120 121

    /**
     * Is media list playing?
     *
     * \return true for playing and false for not playing
     */
122 123
    bool isPlaying()
    {
124
        return libvlc_media_list_player_is_playing(*this) != 0;
125
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
126 127 128 129 130 131

    /**
     * Get current libvlc_state of media list player
     *
     * \return libvlc_state_t for media list player
     */
132 133
    libvlc_state_t state()
    {
134
        return libvlc_media_list_player_get_state( *this );
135
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
136 137 138 139 140 141 142 143

    /**
     * Play media list item at position index
     *
     * \param i_index  index in media list to play
     *
     * \return 0 upon success -1 if the item wasn't found
     */
144 145
    int playItemAtIndex(int i_index)
    {
146
        return libvlc_media_list_player_play_item_at_index(*this, i_index);
147
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
148 149 150 151 152 153 154 155

    /**
     * Play the given media item
     *
     * \param p_md  the media instance
     *
     * \return 0 upon success, -1 if the media is not part of the media list
     */
156
    int playItem(const Media& md)
157
    {
158
        return libvlc_media_list_player_play_item( *this,
159 160
                        getInternalPtr<libvlc_media_t>( md ) );
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
161 162 163 164

    /**
     * Stop playing media list
     */
165 166
    void stop()
    {
167
        libvlc_media_list_player_stop(*this);
168
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
169 170 171 172 173 174

    /**
     * Play next item from media list
     *
     * \return 0 upon success -1 if there is no next item
     */
175 176
    int next()
    {
177
        return libvlc_media_list_player_next(*this);
178
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
179 180 181 182 183 184

    /**
     * Play previous item from media list
     *
     * \return 0 upon success -1 if there is no previous item
     */
185 186
    int previous()
    {
187
        return libvlc_media_list_player_previous(*this);
188
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
189 190 191 192 193 194

    /**
     * Sets the playback mode for the playlist
     *
     * \param e_mode  playback mode specification
     */
195 196
    void setPlaybackMode(libvlc_playback_mode_t e_mode)
    {
197
        libvlc_media_list_player_set_playback_mode(*this, e_mode);
198
    }
199 200

private:
201
    std::shared_ptr<MediaListPlayerEventManager> m_eventManager;
202

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
203 204 205 206 207 208
};

} // namespace VLC

#endif