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, startpos]) -- 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
83 * startpos : [opt] int - starting position when playing a playlist. Default = -1\n
85 * *Note, If item is not given then the Player will try to play the current item\n
86 * in the current playlist.\n
88 * You can use the above as keywords for arguments and skip certain optional arguments.\n
89 * Once you use a keyword, all following arguments require the keyword.\n
92 * - listitem = xbmcgui.ListItem('Ironman')\n
93 * - listitem.setInfo('video', {'Title': 'Ironman', 'Genre': 'Science Fiction'})\n
94 * - xbmc.Player().play(url, listitem, windowed)\n
95 * - xbmc.Player().play(playlist, listitem, windowed, startpos)\n
97 void play(const PlayParameter& item = Player::defaultPlayParameter,
98 const XBMCAddon::xbmcgui::ListItem* listitem = NULL, bool windowed = false, int startpos = -1);
101 * stop() -- Stop playing.
106 * pause() -- Pause playing.
111 * playnext() -- Play next item in playlist.
116 * playprevious() -- Play previous item in playlist.
121 * playselected() -- Play a certain item from the current playlist.
123 void playselected(int selected);
126 * onPlayBackStarted() -- onPlayBackStarted method.
128 * Will be called when xbmc starts playing a file
130 // Player_OnPlayBackStarted
131 virtual void onPlayBackStarted();
135 * onPlayBackEnded() -- onPlayBackEnded method.
137 * Will be called when xbmc stops playing a file
139 // Player_OnPlayBackEnded
140 virtual void onPlayBackEnded();
143 * onPlayBackStopped() -- onPlayBackStopped method.
145 * Will be called when user stops xbmc playing a file
147 // Player_OnPlayBackStopped
148 virtual void onPlayBackStopped();
151 * onPlayBackPaused() -- onPlayBackPaused method.
153 * Will be called when user pauses a playing file
155 // Player_OnPlayBackPaused
156 virtual void onPlayBackPaused();
159 * onPlayBackResumed() -- onPlayBackResumed method.
161 * Will be called when user resumes a paused file
163 // Player_OnPlayBackResumed
164 virtual void onPlayBackResumed();
167 * onQueueNextItem() -- onQueueNextItem method.
169 * Will be called when user queues the next item
171 virtual void onQueueNextItem();
174 * onPlayBackSpeedChanged(speed) -- onPlayBackSpeedChanged method.
176 * speed : integer - current speed of player.
178 * *Note, negative speed means player is rewinding, 1 is normal playback speed.
180 * Will be called when players speed changes. (eg. user FF/RW)
182 virtual void onPlayBackSpeedChanged(int speed);
185 * onPlayBackSeek(time, seekOffset) -- onPlayBackSeek method.
187 * time : integer - time to seek to.\n
188 * seekOffset : integer - ?.
190 * Will be called when user seeks to a time
192 virtual void onPlayBackSeek(int time, int seekOffset);
195 * onPlayBackSeekChapter(chapter) -- onPlayBackSeekChapter method.
197 * chapter : integer - chapter to seek to.
199 * Will be called when user performs a chapter seek
201 virtual void onPlayBackSeekChapter(int chapter);
204 * isPlaying() -- returns True is xbmc is playing a file.
210 * isPlayingAudio() -- returns True is xbmc is playing an audio file.
212 // Player_IsPlayingAudio
213 bool isPlayingAudio();
216 * isPlayingVideo() -- returns True if xbmc is playing a video.
218 // Player_IsPlayingVideo
219 bool isPlayingVideo();
222 * getPlayingFile() -- returns the current playing file as a string.
224 * Throws: Exception, if player is not playing a file.
226 // Player_GetPlayingFile
227 String getPlayingFile() throw (PlayerException);
230 * getTime() -- Returns the current time of the current playing media as fractional seconds.
232 * Throws: Exception, if player is not playing a file.
235 double getTime() throw(PlayerException);
238 * seekTime() -- Seeks the specified amount of time as fractional seconds.
239 * The time specified is relative to the beginning of the
240 * currently playing media file.
242 * Throws: Exception, if player is not playing a file.
245 void seekTime(double seekTime) throw(PlayerException);
248 * setSubtitles() -- set subtitle file and enable subtitlesn
250 // Player_SetSubtitles
251 void setSubtitles(const char* subtitleFile);
253 // Player_ShowSubtitles
255 * showSubtitles(visible) -- enable/disable subtitles
257 * visible : boolean - True for visible subtitles.
260 * - xbmc.Player().showSubtitles(True)
262 void showSubtitles(bool bVisible);
265 * getSubtitles() -- get subtitle stream name
267 // Player_GetSubtitles
268 String getSubtitles();
271 * DisableSubtitles() -- disable subtitles
273 // Player_DisableSubtitles
274 void disableSubtitles();
276 // Player_getAvailableSubtitleStreams
278 * getAvailableSubtitleStreams() -- get Subtitle stream names
280 std::vector<String>* getAvailableSubtitleStreams();
282 // Player_setSubtitleStream
284 * setSubtitleStream(stream) -- set Subtitle Stream
289 * - setSubtitleStream(1)
291 void setSubtitleStream(int iStream);
294 * getVideoInfoTag() -- returns the VideoInfoTag of the current playing Movie.
296 * Throws: Exception, if player is not playing a file or current file is not a movie file.
298 InfoTagVideo* getVideoInfoTag() throw (PlayerException);
301 * getMusicInfoTag() -- returns the MusicInfoTag of the current playing 'Song'.
303 * Throws: Exception, if player is not playing a file or current file is not a music file.
305 // Player_GetMusicInfoTag
306 InfoTagMusic* getMusicInfoTag() throw (PlayerException);
309 *getTotalTime() -- Returns the total time of the current playing media in
310 * seconds. This is only accurate to the full second.
312 *Throws: Exception, if player is not playing a file.
314 double getTotalTime() throw (PlayerException);
316 // Player_getAvailableAudioStreams
318 * getAvailableAudioStreams() -- get Audio stream names
320 std::vector<String>* getAvailableAudioStreams();
323 * setAudioStream(stream) -- set Audio Stream.
329 * - setAudioStream(1)
331 void setAudioStream(int iStream);
334 SWIGHIDDENVIRTUAL void OnPlayBackStarted();
335 SWIGHIDDENVIRTUAL void OnPlayBackEnded();
336 SWIGHIDDENVIRTUAL void OnPlayBackStopped();
337 SWIGHIDDENVIRTUAL void OnPlayBackPaused();
338 SWIGHIDDENVIRTUAL void OnPlayBackResumed();
339 SWIGHIDDENVIRTUAL void OnQueueNextItem();
340 SWIGHIDDENVIRTUAL void OnPlayBackSpeedChanged(int iSpeed);
341 SWIGHIDDENVIRTUAL void OnPlayBackSeek(int iTime, int seekOffset);
342 SWIGHIDDENVIRTUAL void OnPlayBackSeekChapter(int iChapter);