/xbmc/PlayListPlayer.h

http://github.com/xbmc/xbmc · C Header · 203 lines · 76 code · 37 blank · 90 comment · 0 complexity · 82144dd04894bf4d3cee5a1136442339 MD5 · raw file

  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. #pragma once
  9. #include "ServiceBroker.h"
  10. #include "guilib/IMsgTargetCallback.h"
  11. #include "messaging/IMessageTarget.h"
  12. #include <memory>
  13. #define PLAYLIST_NONE -1
  14. #define PLAYLIST_MUSIC 0
  15. #define PLAYLIST_VIDEO 1
  16. #define PLAYLIST_PICTURE 2
  17. class CAction;
  18. class CFileItem; typedef std::shared_ptr<CFileItem> CFileItemPtr;
  19. class CFileItemList;
  20. class CVariant;
  21. namespace PLAYLIST
  22. {
  23. /*!
  24. \ingroup windows
  25. \brief Manages playlist playing.
  26. */
  27. enum REPEAT_STATE { REPEAT_NONE = 0, REPEAT_ONE, REPEAT_ALL };
  28. class CPlayList;
  29. class CPlayListPlayer : public IMsgTargetCallback,
  30. public KODI::MESSAGING::IMessageTarget
  31. {
  32. public:
  33. CPlayListPlayer(void);
  34. ~CPlayListPlayer(void) override;
  35. bool OnMessage(CGUIMessage &message) override;
  36. int GetMessageMask() override;
  37. void OnApplicationMessage(KODI::MESSAGING::ThreadMessage* pMsg) override;
  38. /*! \brief Play the next (or another) entry in the current playlist
  39. \param offset The offset from the current entry (defaults to 1, i.e. the next entry).
  40. \param autoPlay Whether we should start playing if not already (defaults to false).
  41. */
  42. bool PlayNext(int offset = 1, bool autoPlay = false);
  43. /*! \brief Play the previous entry in the current playlist
  44. \sa PlayNext
  45. */
  46. bool PlayPrevious();
  47. bool PlaySongId(int songId);
  48. bool Play();
  49. /*! \brief Creates a new playlist for an item and starts playing it
  50. \param pItem The item to play.
  51. */
  52. bool Play(const CFileItemPtr &pItem, std::string player);
  53. /*! \brief Start playing a particular entry in the current playlist
  54. \param index the index of the item to play. This value is modified to ensure it lies within the current playlist.
  55. \param replace whether this item should replace the currently playing item. See CApplication::PlayFile (defaults to false).
  56. \param playPreviousOnFail whether to go back to the previous item if playback fails (default to false)
  57. */
  58. bool Play(int index, std::string player, bool replace = false, bool playPreviousOnFail = false);
  59. /*! \brief Returns the index of the current item in active playlist.
  60. \return Current item in the active playlist.
  61. \sa SetCurrentSong
  62. */
  63. int GetCurrentSong() const;
  64. /*! \brief Change the current item in the active playlist.
  65. \param index item index in playlist. Set only if the index is within the range of the current playlist.
  66. \sa GetCurrentSong
  67. */
  68. void SetCurrentSong(int index);
  69. int GetNextSong();
  70. /*! \brief Get the index in the playlist that is offset away from the current index in the current playlist.
  71. Obeys any repeat settings (eg repeat one will return the current index regardless of offset)
  72. \return the index of the entry, or -1 if there is no current playlist. There is no guarantee that the returned index is valid.
  73. */
  74. int GetNextSong(int offset) const;
  75. /*! \brief Set the active playlist
  76. \param playList Values can be PLAYLIST_NONE, PLAYLIST_MUSIC or PLAYLIST_VIDEO
  77. \sa GetCurrentPlaylist
  78. */
  79. void SetCurrentPlaylist(int playlist);
  80. /*! \brief Get the currently active playlist
  81. \return PLAYLIST_NONE, PLAYLIST_MUSIC or PLAYLIST_VIDEO
  82. \sa SetCurrentPlaylist, GetPlaylist
  83. */
  84. int GetCurrentPlaylist() const;
  85. /*! \brief Get a particular playlist object
  86. \param playList Values can be PLAYLIST_MUSIC or PLAYLIST_VIDEO
  87. \return A reference to the CPlayList object.
  88. \sa GetCurrentPlaylist
  89. */
  90. CPlayList& GetPlaylist(int playlist);
  91. const CPlayList& GetPlaylist(int iPlaylist) const;
  92. /*! \brief Removes any item from all playlists located on a removable share
  93. \return Number of items removed from PLAYLIST_MUSIC and PLAYLIST_VIDEO
  94. */
  95. int RemoveDVDItems();
  96. /*! \brief Resets the current song and unplayable counts.
  97. Does not alter the active playlist.
  98. */
  99. void Reset();
  100. void ClearPlaylist(int iPlaylist);
  101. void Clear();
  102. /*! \brief Set shuffle state of a playlist.
  103. If the shuffle state changes, the playlist is shuffled or unshuffled.
  104. Has no effect if Party Mode is enabled.
  105. \param playlist the playlist to (un)shuffle, PLAYLIST_MUSIC or PLAYLIST_VIDEO.
  106. \param shuffle set true to shuffle, false to unshuffle.
  107. \param notify notify the user with a Toast notification (defaults to false)
  108. \sa IsShuffled
  109. */
  110. void SetShuffle(int playlist, bool shuffle, bool notify = false);
  111. /*! \brief Return whether a playlist is shuffled.
  112. If partymode is enabled, this always returns false.
  113. \param playlist the playlist to query for shuffle state, PLAYLIST_MUSIC or PLAYLIST_VIDEO.
  114. \return true if the given playlist is shuffled and party mode isn't enabled, false otherwise.
  115. \sa SetShuffle
  116. */
  117. bool IsShuffled(int iPlaylist) const;
  118. /*! \brief Return whether or not something has been played yet from the current playlist.
  119. \return true if something has been played, false otherwise.
  120. */
  121. bool HasPlayedFirstFile() const;
  122. /*! \brief Set repeat state of a playlist.
  123. If called while in Party Mode, repeat is disabled.
  124. \param playlist the playlist to set repeat state for, PLAYLIST_MUSIC or PLAYLIST_VIDEO.
  125. \param state set to REPEAT_NONE, REPEAT_ONE or REPEAT_ALL
  126. \param notify notify the user with a Toast notification
  127. \sa GetRepeat
  128. */
  129. void SetRepeat(int iPlaylist, REPEAT_STATE state, bool notify = false);
  130. REPEAT_STATE GetRepeat(int iPlaylist) const;
  131. // add items via the playlist player
  132. void Add(int iPlaylist, const CPlayList& playlist);
  133. void Add(int iPlaylist, const CFileItemPtr &pItem);
  134. void Add(int iPlaylist, const CFileItemList& items);
  135. void Insert(int iPlaylist, const CPlayList& playlist, int iIndex);
  136. void Insert(int iPlaylist, const CFileItemPtr &pItem, int iIndex);
  137. void Insert(int iPlaylist, const CFileItemList& items, int iIndex);
  138. void Remove(int iPlaylist, int iPosition);
  139. void Swap(int iPlaylist, int indexItem1, int indexItem2);
  140. bool IsSingleItemNonRepeatPlaylist() const;
  141. bool OnAction(const CAction &action);
  142. protected:
  143. /*! \brief Returns true if the given is set to repeat all
  144. \param playlist Playlist to be query
  145. \return true if the given playlist is set to repeat all, false otherwise.
  146. */
  147. bool Repeated(int playlist) const;
  148. /*! \brief Returns true if the given is set to repeat one
  149. \param playlist Playlist to be query
  150. \return true if the given playlist is set to repeat one, false otherwise.
  151. */
  152. bool RepeatedOne(int playlist) const;
  153. void ReShuffle(int iPlaylist, int iPosition);
  154. void AnnouncePropertyChanged(int iPlaylist, const std::string &strProperty, const CVariant &value);
  155. bool m_bPlayedFirstFile;
  156. bool m_bPlaybackStarted;
  157. int m_iFailedSongs;
  158. unsigned int m_failedSongsStart;
  159. int m_iCurrentSong;
  160. int m_iCurrentPlayList;
  161. CPlayList* m_PlaylistMusic;
  162. CPlayList* m_PlaylistVideo;
  163. CPlayList* m_PlaylistEmpty;
  164. REPEAT_STATE m_repeatState[2];
  165. };
  166. }