2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
11 #include "guilib/IMsgTargetCallback.h"
12 #include "messaging/IMessageTarget.h"
13 #include "playlists/PlayListTypes.h"
20 class CFileItem
; typedef std::shared_ptr
<CFileItem
> CFileItemPtr
;
25 namespace KODI::PLAYLIST
29 class CPlayListPlayer
: public IMsgTargetCallback
,
30 public KODI::MESSAGING::IMessageTarget
34 CPlayListPlayer(void);
35 ~CPlayListPlayer(void) override
;
36 bool OnMessage(CGUIMessage
&message
) override
;
38 int GetMessageMask() override
;
39 void OnApplicationMessage(KODI::MESSAGING::ThreadMessage
* pMsg
) override
;
41 /*! \brief Play the next (or another) entry in the current playlist
42 \param offset The offset from the current entry (defaults to 1, i.e. the next entry).
43 \param autoPlay Whether we should start playing if not already (defaults to false).
45 bool PlayNext(int offset
= 1, bool autoPlay
= false);
47 /*! \brief Play the previous entry in the current playlist
51 bool PlayItemIdx(int itemIdx
);
55 * \brief Creates a new playlist for an item and starts playing it
56 * \param pItem The item to play.
57 * \param player The player name.
58 * \param forceSelection for Blurays, force simple menu to change playlist (default to false)
59 * \return True if has success, otherwise false.
61 bool Play(const CFileItemPtr
& pItem
, const std::string
& player
, bool forceSelection
= false);
63 /*! \brief Start playing a particular entry in the current playlist
64 \param index the index of the item to play. This value is modified to ensure it lies within the current playlist.
65 \param replace whether this item should replace the currently playing item. See CApplication::PlayFile (defaults to false).
66 \param playPreviousOnFail whether to go back to the previous item if playback fails (default to false)
67 \param forceSelection for Blurays, force simple menu to change playlist (default to false)
70 const std::string
& player
,
72 bool playPreviousOnFail
= false,
73 bool forceSelection
= false);
75 /*! \brief Returns the index of the current item in active playlist.
76 \return Current item in the active playlist.
79 int GetCurrentItemIdx() const;
81 /*! \brief Change the current item in the active playlist.
82 \param index item index in playlist. Set only if the index is within the range of the current playlist.
85 void SetCurrentItemIdx(int index
);
89 /*! \brief Get the index in the playlist that is offset away from the current index in the current playlist.
90 Obeys any repeat settings (eg repeat one will return the current index regardless of offset)
91 \return the index of the entry, or -1 if there is no current playlist. There is no guarantee that the returned index is valid.
93 int GetNextItemIdx(int offset
) const;
95 /*! \brief Set the active playlist
96 \param id Id of playlist
97 \sa GetCurrentPlaylist
99 void SetCurrentPlaylist(Id playlistId
);
101 /*! \brief Get the currently active playlist
102 \return Id of playlist
103 \sa SetCurrentPlaylist, GetPlaylist
105 Id
GetCurrentPlaylist() const;
107 /*! \brief Get a particular playlist object
108 \param id Id of playlist
109 \return A reference to the CPlayList object.
110 \sa GetCurrentPlaylist
112 CPlayList
& GetPlaylist(Id playlistId
);
113 const CPlayList
& GetPlaylist(Id playlistId
) const;
115 /*! \brief Removes any item from all playlists located on a removable share
116 \return Number of items removed from PLAYLIST::TYPE_MUSIC and PLAYLIST::TYPE_VIDEO
118 int RemoveDVDItems();
120 /*! \brief Resets the current song and unplayable counts.
121 Does not alter the active playlist.
125 void ClearPlaylist(Id playlistId
);
128 /*! \brief Set shuffle state of a playlist.
129 If the shuffle state changes, the playlist is shuffled or unshuffled.
130 Has no effect if Party Mode is enabled.
131 \param playlist the playlist to (un)shuffle, PLAYLIST::TYPE_MUSIC or PLAYLIST::TYPE_VIDEO.
132 \param shuffle set true to shuffle, false to unshuffle.
133 \param notify notify the user with a Toast notification (defaults to false)
136 void SetShuffle(Id playlistId
, bool shuffle
, bool notify
= false);
138 /*! \brief Return whether a playlist is shuffled.
139 If partymode is enabled, this always returns false.
140 \param playlist the playlist to query for shuffle state, PLAYLIST::TYPE_MUSIC or PLAYLIST::TYPE_VIDEO.
141 \return true if the given playlist is shuffled and party mode isn't enabled, false otherwise.
144 bool IsShuffled(Id playlistId
) const;
146 /*! \brief Return whether or not something has been played yet from the current playlist.
147 \return true if something has been played, false otherwise.
149 bool HasPlayedFirstFile() const;
151 /*! \brief Set repeat state of a playlist.
152 If called while in Party Mode, repeat is disabled.
153 \param playlist the playlist to set repeat state for, PLAYLIST::TYPE_MUSIC or PLAYLIST::TYPE_VIDEO.
154 \param state set to RepeatState::NONE, RepeatState::ONE or RepeatState::ALL
155 \param notify notify the user with a Toast notification
158 void SetRepeat(Id playlistId
, RepeatState state
, bool notify
= false);
159 RepeatState
GetRepeat(Id playlistId
) const;
161 // add items via the playlist player
162 void Add(Id playlistId
, const CPlayList
& playlist
);
163 void Add(Id playlistId
, const CFileItemPtr
& pItem
);
164 void Add(Id playlistId
, const CFileItemList
& items
);
165 void Insert(Id playlistId
, const CPlayList
& playlist
, int iIndex
);
166 void Insert(Id playlistId
, const CFileItemPtr
& pItem
, int iIndex
);
167 void Insert(Id playlistId
, const CFileItemList
& items
, int iIndex
);
168 void Remove(Id playlistId
, int iPosition
);
169 void Swap(Id playlistId
, int indexItem1
, int indexItem2
);
171 bool IsSingleItemNonRepeatPlaylist() const;
173 bool OnAction(const CAction
&action
);
176 /*! \brief Returns true if the given is set to repeat all
177 \param playlist Playlist to be query
178 \return true if the given playlist is set to repeat all, false otherwise.
180 bool Repeated(Id playlistId
) const;
182 /*! \brief Returns true if the given is set to repeat one
183 \param playlist Playlist to be query
184 \return true if the given playlist is set to repeat one, false otherwise.
186 bool RepeatedOne(Id playlistId
) const;
188 void ReShuffle(Id playlistId
, int iPosition
);
190 void AnnouncePropertyChanged(Id playlistId
,
191 const std::string
& strProperty
,
192 const CVariant
& value
);
194 bool m_bPlayedFirstFile
;
195 bool m_bPlaybackStarted
;
197 std::chrono::time_point
<std::chrono::steady_clock
> m_failedSongsStart
;
199 Id m_iCurrentPlayList
{Id::TYPE_NONE
};
200 CPlayList
* m_PlaylistMusic
;
201 CPlayList
* m_PlaylistVideo
;
202 CPlayList
* m_PlaylistEmpty
;
203 std::map
<Id
, RepeatState
> m_repeatState
{
204 {Id::TYPE_MUSIC
, RepeatState::NONE
},
205 {Id::TYPE_VIDEO
, RepeatState::NONE
},
206 {Id::TYPE_PICTURE
, RepeatState::NONE
},
210 } // namespace KODI::PLAYLIST