[video] fix selection after changing video or extra art
[xbmc.git] / xbmc / PlayListPlayer.h
blob961aaf28d4023b1ee2cfcc9c87c0f89eac9ca43f
1 /*
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.
7 */
9 #pragma once
11 #include "guilib/IMsgTargetCallback.h"
12 #include "messaging/IMessageTarget.h"
13 #include "playlists/PlayListTypes.h"
15 #include <chrono>
16 #include <map>
17 #include <memory>
19 class CAction;
20 class CFileItem; typedef std::shared_ptr<CFileItem> CFileItemPtr;
21 class CFileItemList;
23 class CVariant;
25 namespace PLAYLIST
27 class CPlayList;
29 class CPlayListPlayer : public IMsgTargetCallback,
30 public KODI::MESSAGING::IMessageTarget
33 public:
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
48 \sa PlayNext
50 bool PlayPrevious();
51 bool PlayItemIdx(int itemIdx);
52 bool Play();
54 /*!
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 * \return True if has success, otherwise false.
60 bool Play(const CFileItemPtr& pItem, const std::string& player);
62 /*! \brief Start playing a particular entry in the current playlist
63 \param index the index of the item to play. This value is modified to ensure it lies within the current playlist.
64 \param replace whether this item should replace the currently playing item. See CApplication::PlayFile (defaults to false).
65 \param playPreviousOnFail whether to go back to the previous item if playback fails (default to false)
67 bool Play(int index,
68 const std::string& player,
69 bool replace = false,
70 bool playPreviousOnFail = false);
72 /*! \brief Returns the index of the current item in active playlist.
73 \return Current item in the active playlist.
74 \sa SetCurrentItemIdx
76 int GetCurrentItemIdx() const;
78 /*! \brief Change the current item in the active playlist.
79 \param index item index in playlist. Set only if the index is within the range of the current playlist.
80 \sa GetCurrentItemIdx
82 void SetCurrentItemIdx(int index);
84 int GetNextItemIdx();
86 /*! \brief Get the index in the playlist that is offset away from the current index in the current playlist.
87 Obeys any repeat settings (eg repeat one will return the current index regardless of offset)
88 \return the index of the entry, or -1 if there is no current playlist. There is no guarantee that the returned index is valid.
90 int GetNextItemIdx(int offset) const;
92 /*! \brief Set the active playlist
93 \param id Values can be PLAYLIST::TYPE_NONE, PLAYLIST::TYPE_MUSIC or PLAYLIST::TYPE_VIDEO
94 \sa GetCurrentPlaylist
96 void SetCurrentPlaylist(PLAYLIST::Id playlistId);
98 /*! \brief Get the currently active playlist
99 \return PLAYLIST::TYPE_NONE, PLAYLIST::TYPE_MUSIC or PLAYLIST::TYPE_VIDEO
100 \sa SetCurrentPlaylist, GetPlaylist
102 PLAYLIST::Id GetCurrentPlaylist() const;
104 /*! \brief Get a particular playlist object
105 \param id Values can be PLAYLIST::TYPE_MUSIC or PLAYLIST::TYPE_VIDEO
106 \return A reference to the CPlayList object.
107 \sa GetCurrentPlaylist
109 CPlayList& GetPlaylist(PLAYLIST::Id playlistId);
110 const CPlayList& GetPlaylist(PLAYLIST::Id playlistId) const;
112 /*! \brief Removes any item from all playlists located on a removable share
113 \return Number of items removed from PLAYLIST::TYPE_MUSIC and PLAYLIST::TYPE_VIDEO
115 int RemoveDVDItems();
117 /*! \brief Resets the current song and unplayable counts.
118 Does not alter the active playlist.
120 void Reset();
122 void ClearPlaylist(PLAYLIST::Id playlistId);
123 void Clear();
125 /*! \brief Set shuffle state of a playlist.
126 If the shuffle state changes, the playlist is shuffled or unshuffled.
127 Has no effect if Party Mode is enabled.
128 \param playlist the playlist to (un)shuffle, PLAYLIST::TYPE_MUSIC or PLAYLIST::TYPE_VIDEO.
129 \param shuffle set true to shuffle, false to unshuffle.
130 \param notify notify the user with a Toast notification (defaults to false)
131 \sa IsShuffled
133 void SetShuffle(PLAYLIST::Id playlistId, bool shuffle, bool notify = false);
135 /*! \brief Return whether a playlist is shuffled.
136 If partymode is enabled, this always returns false.
137 \param playlist the playlist to query for shuffle state, PLAYLIST::TYPE_MUSIC or PLAYLIST::TYPE_VIDEO.
138 \return true if the given playlist is shuffled and party mode isn't enabled, false otherwise.
139 \sa SetShuffle
141 bool IsShuffled(PLAYLIST::Id playlistId) const;
143 /*! \brief Return whether or not something has been played yet from the current playlist.
144 \return true if something has been played, false otherwise.
146 bool HasPlayedFirstFile() const;
148 /*! \brief Set repeat state of a playlist.
149 If called while in Party Mode, repeat is disabled.
150 \param playlist the playlist to set repeat state for, PLAYLIST::TYPE_MUSIC or PLAYLIST::TYPE_VIDEO.
151 \param state set to RepeatState::NONE, RepeatState::ONE or RepeatState::ALL
152 \param notify notify the user with a Toast notification
153 \sa GetRepeat
155 void SetRepeat(PLAYLIST::Id playlistId, PLAYLIST::RepeatState state, bool notify = false);
156 PLAYLIST::RepeatState GetRepeat(PLAYLIST::Id playlistId) const;
158 // add items via the playlist player
159 void Add(PLAYLIST::Id playlistId, const CPlayList& playlist);
160 void Add(PLAYLIST::Id playlistId, const CFileItemPtr& pItem);
161 void Add(PLAYLIST::Id playlistId, const CFileItemList& items);
162 void Insert(PLAYLIST::Id playlistId, const CPlayList& playlist, int iIndex);
163 void Insert(PLAYLIST::Id playlistId, const CFileItemPtr& pItem, int iIndex);
164 void Insert(PLAYLIST::Id playlistId, const CFileItemList& items, int iIndex);
165 void Remove(PLAYLIST::Id playlistId, int iPosition);
166 void Swap(PLAYLIST::Id playlistId, int indexItem1, int indexItem2);
168 bool IsSingleItemNonRepeatPlaylist() const;
170 bool OnAction(const CAction &action);
171 protected:
172 /*! \brief Returns true if the given is set to repeat all
173 \param playlist Playlist to be query
174 \return true if the given playlist is set to repeat all, false otherwise.
176 bool Repeated(PLAYLIST::Id playlistId) const;
178 /*! \brief Returns true if the given is set to repeat one
179 \param playlist Playlist to be query
180 \return true if the given playlist is set to repeat one, false otherwise.
182 bool RepeatedOne(PLAYLIST::Id playlistId) const;
184 void ReShuffle(PLAYLIST::Id playlistId, int iPosition);
186 void AnnouncePropertyChanged(PLAYLIST::Id playlistId,
187 const std::string& strProperty,
188 const CVariant& value);
190 bool m_bPlayedFirstFile;
191 bool m_bPlaybackStarted;
192 int m_iFailedSongs;
193 std::chrono::time_point<std::chrono::steady_clock> m_failedSongsStart;
194 int m_iCurrentSong;
195 PLAYLIST::Id m_iCurrentPlayList{PLAYLIST::TYPE_NONE};
196 CPlayList* m_PlaylistMusic;
197 CPlayList* m_PlaylistVideo;
198 CPlayList* m_PlaylistEmpty;
199 std::map<PLAYLIST::Id, PLAYLIST::RepeatState> m_repeatState{
200 {PLAYLIST::TYPE_MUSIC, PLAYLIST::RepeatState::NONE},
201 {PLAYLIST::TYPE_VIDEO, PLAYLIST::RepeatState::NONE},
202 {PLAYLIST::TYPE_PICTURE, PLAYLIST::RepeatState::NONE},