2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
23 #include "cores/playercorefactory/PlayerCoreFactory.h"
27 #include "InfoTagVideo.h"
28 #include "Exception.h"
29 #include "music/tags/MusicInfoTag.h"
30 #include "AddonString.h"
31 #include "InfoTagMusic.h"
32 #include "AddonCallback.h"
33 #include "Alternative.h"
35 #include "swighelper.h"
41 XBMCCOMMONS_STANDARD_EXCEPTION(PlayerException);
43 typedef Alternative<String, const PlayList* > PlayParameter;
45 // This class is a merge of what was previously in xbmcmodule/player.h
46 // and xbmcmodule/PythonPlayer.h without the python references. The
47 // queuing and handling of asynchronous callbacks is done internal to
53 * Player() -- Creates a new Player class.
55 class Player : public AddonCallback, public IPlayerCallback
59 EPLAYERCORES playerCore;
61 void playStream(const String& item = emptyString, const XBMCAddon::xbmcgui::ListItem* listitem = NULL, bool windowed = false);
62 void playPlaylist(const PlayList* playlist = NULL,
63 bool windowed = false, int startpos=-1);
64 void playCurrent(bool windowed = false);
68 static PlayParameter defaultPlayParameter;
71 // Construct a Player proxying the given generated binding. The
72 // construction of a Player needs to identify whether or not any
73 // callbacks will be executed asynchronously or not.
74 Player(int playerCore = EPC_NONE);
75 virtual ~Player(void);
78 * play([item, listitem, windowed]) -- Play this item.\n
80 * item : [opt] string - filename, url or playlist.\n
81 * listitem : [opt] listitem - used with setInfo() to set different infolabels.\n
82 * windowed : [opt] bool - true=play video windowed, false=play users preference.(default)\n
84 * *Note, If item is not given then the Player will try to play the current item\n
85 * in the current playlist.\n
87 * You can use the above as keywords for arguments and skip certain optional arguments.\n
88 * Once you use a keyword, all following arguments require the keyword.\n
91 * - listitem = xbmcgui.ListItem('Ironman')\n
92 * - listitem.setInfo('video', {'Title': 'Ironman', 'Genre': 'Science Fiction'})\n
93 * - xbmc.Player().play(url, listitem, windowed)\n
95 void play(const PlayParameter& item = Player::defaultPlayParameter,
96 const XBMCAddon::xbmcgui::ListItem* listitem = NULL, bool windowed = false, int startpos = -1);
99 * stop() -- Stop playing.
104 * pause() -- Pause playing.
109 * playnext() -- Play next item in playlist.
114 * playprevious() -- Play previous item in playlist.
119 * playselected() -- Play a certain item from the current playlist.
121 void playselected(int selected);
124 * onPlayBackStarted() -- onPlayBackStarted method.
126 * Will be called when xbmc starts playing a file
128 // Player_OnPlayBackStarted
129 virtual void onPlayBackStarted();
133 * onPlayBackEnded() -- onPlayBackEnded method.
135 * Will be called when xbmc stops playing a file
137 // Player_OnPlayBackEnded
138 virtual void onPlayBackEnded();
141 * onPlayBackStopped() -- onPlayBackStopped method.
143 * Will be called when user stops xbmc playing a file
145 // Player_OnPlayBackStopped
146 virtual void onPlayBackStopped();
149 * onPlayBackPaused() -- onPlayBackPaused method.
151 * Will be called when user pauses a playing file
153 // Player_OnPlayBackPaused
154 virtual void onPlayBackPaused();
157 * onPlayBackResumed() -- onPlayBackResumed method.
159 * Will be called when user resumes a paused file
161 // Player_OnPlayBackResumed
162 virtual void onPlayBackResumed();
165 * onQueueNextItem() -- onQueueNextItem method.
167 * Will be called when user queues the next item
169 virtual void onQueueNextItem();
172 * onPlayBackSpeedChanged(speed) -- onPlayBackSpeedChanged method.
174 * speed : integer - current speed of player.
176 * *Note, negative speed means player is rewinding, 1 is normal playback speed.
178 * Will be called when players speed changes. (eg. user FF/RW)
180 virtual void onPlayBackSpeedChanged(int speed);
183 * onPlayBackSeek(time, seekOffset) -- onPlayBackSeek method.
185 * time : integer - time to seek to.\n
186 * seekOffset : integer - ?.
188 * Will be called when user seeks to a time
190 virtual void onPlayBackSeek(int time, int seekOffset);
193 * onPlayBackSeekChapter(chapter) -- onPlayBackSeekChapter method.
195 * chapter : integer - chapter to seek to.
197 * Will be called when user performs a chapter seek
199 virtual void onPlayBackSeekChapter(int chapter);
202 * isPlaying() -- returns True is xbmc is playing a file.
208 * isPlayingAudio() -- returns True is xbmc is playing an audio file.
210 // Player_IsPlayingAudio
211 bool isPlayingAudio();
214 * isPlayingVideo() -- returns True if xbmc is playing a video.
216 // Player_IsPlayingVideo
217 bool isPlayingVideo();
220 * getPlayingFile() -- returns the current playing file as a string.
222 * Throws: Exception, if player is not playing a file.
224 // Player_GetPlayingFile
225 String getPlayingFile() throw (PlayerException);
228 * getTime() -- Returns the current time of the current playing media as fractional seconds.
230 * Throws: Exception, if player is not playing a file.
233 double getTime() throw(PlayerException);
236 * seekTime() -- Seeks the specified amount of time as fractional seconds.
237 * The time specified is relative to the beginning of the
238 * currently playing media file.
240 * Throws: Exception, if player is not playing a file.
243 void seekTime(double seekTime) throw(PlayerException);
246 * setSubtitles() -- set subtitle file and enable subtitlesn
248 // Player_SetSubtitles
249 void setSubtitles(const char* subtitleFile);
251 // Player_ShowSubtitles
253 * showSubtitles(visible) -- enable/disable subtitles
255 * visible : boolean - True for visible subtitles.
258 * - xbmc.Player().showSubtitles(True)
260 void showSubtitles(bool bVisible);
263 * getSubtitles() -- get subtitle stream name
265 // Player_GetSubtitles
266 String getSubtitles();
269 * DisableSubtitles() -- disable subtitles
271 // Player_DisableSubtitles
272 void disableSubtitles();
274 // Player_getAvailableSubtitleStreams
276 * getAvailableSubtitleStreams() -- get Subtitle stream names
278 std::vector<String>* getAvailableSubtitleStreams();
280 // Player_setSubtitleStream
282 * setSubtitleStream(stream) -- set Subtitle Stream
287 * - setSubtitleStream(1)
289 void setSubtitleStream(int iStream);
292 * getVideoInfoTag() -- returns the VideoInfoTag of the current playing Movie.
294 * Throws: Exception, if player is not playing a file or current file is not a movie file.
296 InfoTagVideo* getVideoInfoTag() throw (PlayerException);
299 * getMusicInfoTag() -- returns the MusicInfoTag of the current playing 'Song'.
301 * Throws: Exception, if player is not playing a file or current file is not a music file.
303 // Player_GetMusicInfoTag
304 InfoTagMusic* getMusicInfoTag() throw (PlayerException);
307 *getTotalTime() -- Returns the total time of the current playing media in
308 * seconds. This is only accurate to the full second.
310 *Throws: Exception, if player is not playing a file.
312 double getTotalTime() throw (PlayerException);
314 // Player_getAvailableAudioStreams
316 * getAvailableAudioStreams() -- get Audio stream names
318 std::vector<String>* getAvailableAudioStreams();
321 * setAudioStream(stream) -- set Audio Stream.
327 * - setAudioStream(1)
329 void setAudioStream(int iStream);
332 SWIGHIDDENVIRTUAL void OnPlayBackStarted();
333 SWIGHIDDENVIRTUAL void OnPlayBackEnded();
334 SWIGHIDDENVIRTUAL void OnPlayBackStopped();
335 SWIGHIDDENVIRTUAL void OnPlayBackPaused();
336 SWIGHIDDENVIRTUAL void OnPlayBackResumed();
337 SWIGHIDDENVIRTUAL void OnQueueNextItem();
338 SWIGHIDDENVIRTUAL void OnPlayBackSpeedChanged(int iSpeed);
339 SWIGHIDDENVIRTUAL void OnPlayBackSeek(int iTime, int seekOffset);
340 SWIGHIDDENVIRTUAL void OnPlayBackSeekChapter(int iChapter);