MediaListPlayer.hpp 5.21 KB
Newer Older
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
1
/*****************************************************************************
2
 * MediaListPlayer.hpp: MediaListPlayer API
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
3
 *****************************************************************************
4
 * Copyright © 2015 libvlcpp authors & VideoLAN
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
5
 *
6
 * Authors: Alexey Sokolov <alexey+vlc@asokolov.org>
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
    {
    }

62 63 64 65 66 67
    /**
     * Create an empty VLC MediaListPlayer instance.
     *
     * Calling any method on such an instance is undefined.
    */
    MediaListPlayer() = default;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
68 69 70 71 72 73

    /**
     * Return the event manager of this media_list_player.
     *
     * \return the event manager
     */
74
    MediaListPlayerEventManager& eventManager()
75
    {
76
        if ( m_eventManager == nullptr )
77
        {
78
            libvlc_event_manager_t* obj = libvlc_media_list_player_event_manager(*this);
79
            m_eventManager = std::make_shared<MediaListPlayerEventManager>( obj );
80
        }
81
        return *m_eventManager;
82 83
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
84 85 86 87 88 89

    /**
     * Replace media player in media_list_player with this instance.
     *
     * \param p_mi  media player instance
     */
90
    void setMediaPlayer(const MediaPlayer& mi)
91
    {
92
        libvlc_media_list_player_set_media_player( *this,
93 94
                        getInternalPtr<libvlc_media_player_t>( mi ) );
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
95 96 97 98 99 100

    /**
     * Set the media list associated with the player
     *
     * \param p_mlist  list of media
     */
101
    void setMediaList(const MediaList& mlist)
102
    {
103
        libvlc_media_list_player_set_media_list( *this,
104 105
                            getInternalPtr<libvlc_media_list_t>( mlist ) );
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
106 107 108 109

    /**
     * Play media list
     */
110 111
    void play()
    {
112
        libvlc_media_list_player_play(*this);
113
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
114 115 116 117

    /**
     * Toggle pause (or resume) media list
     */
118 119
    void pause()
    {
120
        libvlc_media_list_player_pause(*this);
121
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
122 123 124 125 126 127

    /**
     * Is media list playing?
     *
     * \return true for playing and false for not playing
     */
128 129
    bool isPlaying()
    {
130
        return libvlc_media_list_player_is_playing(*this) != 0;
131
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
132 133 134 135 136 137

    /**
     * Get current libvlc_state of media list player
     *
     * \return libvlc_state_t for media list player
     */
138 139
    libvlc_state_t state()
    {
140
        return libvlc_media_list_player_get_state( *this );
141
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
142 143 144 145 146 147

    /**
     * Play media list item at position index
     *
     * \param i_index  index in media list to play
     */
148
    bool playItemAtIndex(int i_index)
149
    {
150
        return libvlc_media_list_player_play_item_at_index(*this, i_index) == 0;
151
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
152 153 154 155 156 157

    /**
     * Play the given media item
     *
     * \param p_md  the media instance
     */
158
    bool playItem(const Media& md)
159
    {
160
        return libvlc_media_list_player_play_item( *this,
161
                        getInternalPtr<libvlc_media_t>( md ) ) == 0;
162
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
163 164 165 166

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

    /**
     * Play next item from media list
     */
175
    bool next()
176
    {
177
        return libvlc_media_list_player_next(*this) == 0;
178
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
179 180 181 182

    /**
     * Play previous item from media list
     */
183
    bool previous()
184
    {
185
        return libvlc_media_list_player_previous(*this) == 0;
186
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
187 188 189 190 191 192

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

private:
199
    std::shared_ptr<MediaListPlayerEventManager> m_eventManager;
200

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

} // namespace VLC

#endif