PageRenderTime 50ms CodeModel.GetById 17ms app.highlight 25ms RepoModel.GetById 1ms app.codeStats 0ms

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