xbmc
PlayListPlayer.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
12 #include "messaging/IMessageTarget.h"
13 #include "playlists/PlayListTypes.h"
14 
15 #include <chrono>
16 #include <map>
17 #include <memory>
18 
19 class CAction;
20 class CFileItem; typedef std::shared_ptr<CFileItem> CFileItemPtr;
21 class CFileItemList;
22 
23 class CVariant;
24 
25 namespace PLAYLIST
26 {
27 class CPlayList;
28 
31 {
32 
33 public:
34  CPlayListPlayer(void);
35  ~CPlayListPlayer(void) override;
36  bool OnMessage(CGUIMessage &message) override;
37 
38  int GetMessageMask() override;
40 
45  bool PlayNext(int offset = 1, bool autoPlay = false);
46 
50  bool PlayPrevious();
51  bool PlaySongId(int songId);
52  bool Play();
53 
60  bool Play(const CFileItemPtr& pItem, const std::string& player);
61 
67  bool Play(int index,
68  const std::string& player,
69  bool replace = false,
70  bool playPreviousOnFail = false);
71 
76  int GetCurrentSong() const;
77 
82  void SetCurrentSong(int index);
83 
84  int GetNextSong();
85 
90  int GetNextSong(int offset) const;
91 
96  void SetCurrentPlaylist(PLAYLIST::Id playlistId);
97 
102  PLAYLIST::Id GetCurrentPlaylist() const;
103 
109  CPlayList& GetPlaylist(PLAYLIST::Id playlistId);
110  const CPlayList& GetPlaylist(PLAYLIST::Id playlistId) const;
111 
115  int RemoveDVDItems();
116 
120  void Reset();
121 
122  void ClearPlaylist(PLAYLIST::Id playlistId);
123  void Clear();
124 
133  void SetShuffle(PLAYLIST::Id playlistId, bool shuffle, bool notify = false);
134 
141  bool IsShuffled(PLAYLIST::Id playlistId) const;
142 
146  bool HasPlayedFirstFile() const;
147 
155  void SetRepeat(PLAYLIST::Id playlistId, PLAYLIST::RepeatState state, bool notify = false);
156  PLAYLIST::RepeatState GetRepeat(PLAYLIST::Id playlistId) const;
157 
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);
167 
168  bool IsSingleItemNonRepeatPlaylist() const;
169 
170  bool OnAction(const CAction &action);
171 protected:
176  bool Repeated(PLAYLIST::Id playlistId) const;
177 
182  bool RepeatedOne(PLAYLIST::Id playlistId) const;
183 
184  void ReShuffle(PLAYLIST::Id playlistId, int iPosition);
185 
186  void AnnouncePropertyChanged(PLAYLIST::Id playlistId,
187  const std::string& strProperty,
188  const CVariant& value);
189 
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},
203  };
204 };
205 
206 }
void SetShuffle(PLAYLIST::Id playlistId, bool shuffle, bool notify=false)
Set shuffle state of a playlist. If the shuffle state changes, the playlist is shuffled or unshuffled...
Definition: PlayListPlayer.cpp:523
Definition: Application.h:64
A class wishing to receive messages should implement this and call.
Definition: IMessageTarget.h:23
std::shared_ptr< CFileItem > CFileItemPtr
A shared pointer to CFileItem.
Definition: FileItem.h:680
Represents a list of files.
Definition: FileItem.h:713
bool RepeatedOne(PLAYLIST::Id playlistId) const
Returns true if the given is set to repeat one.
Definition: PlayListPlayer.cpp:515
Definition: ThreadMessage.h:25
CPlayList & GetPlaylist(PLAYLIST::Id playlistId)
Get a particular playlist object.
Definition: PlayListPlayer.cpp:449
PLAYLIST::Id GetCurrentPlaylist() const
Get the currently active playlist.
Definition: PlayListPlayer.cpp:417
Definition: Variant.h:29
Definition: IMsgTargetCallback.h:22
Definition: PlayList.h:23
class encapsulating information regarding a particular user action to be sent to windows and controls...
Definition: Action.h:22
void Reset()
Resets the current song and unplayable counts. Does not alter the active playlist.
Definition: PlayListPlayer.cpp:491
void OnApplicationMessage(KODI::MESSAGING::ThreadMessage *pMsg) override
This gets called whenever a message matching the registered message mask is processed.
Definition: PlayListPlayer.cpp:819
void SetCurrentPlaylist(PLAYLIST::Id playlistId)
Set the active playlist.
Definition: PlayListPlayer.cpp:422
int GetMessageMask() override
Should return the message mask that it wishes to receive messages for.
Definition: PlayListPlayer.cpp:814
bool Repeated(PLAYLIST::Id playlistId) const
Returns true if the given is set to repeat all.
Definition: PlayListPlayer.cpp:507
bool HasPlayedFirstFile() const
Return whether or not something has been played yet from the current playlist.
Definition: PlayListPlayer.cpp:502
int GetCurrentSong() const
Returns the index of the current item in active playlist.
Definition: PlayListPlayer.cpp:412
Definition: GUIMessage.h:365
void SetCurrentSong(int index)
Change the current item in the active playlist.
Definition: PlayListPlayer.cpp:406
int RemoveDVDItems()
Removes any item from all playlists located on a removable share.
Definition: PlayListPlayer.cpp:483
void SetRepeat(PLAYLIST::Id playlistId, PLAYLIST::RepeatState state, bool notify=false)
Set repeat state of a playlist. If called while in Party Mode, repeat is disabled.
Definition: PlayListPlayer.cpp:588
Definition: PlayListPlayer.h:29
bool PlayPrevious()
Play the previous entry in the current playlist.
Definition: PlayListPlayer.cpp:203
bool IsShuffled(PLAYLIST::Id playlistId) const
Return whether a playlist is shuffled. If partymode is enabled, this always returns false...
Definition: PlayListPlayer.cpp:576
bool PlayNext(int offset=1, bool autoPlay=false)
Play the next (or another) entry in the current playlist.
Definition: PlayListPlayer.cpp:183
Represents a file on a share.
Definition: FileItem.h:102