28e38ed6771c49fb83bd0fcf6dacf7379908e219
[vuplus_xbmc] / xbmc / interfaces / legacy / Player.h
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://xbmc.org
4  *
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)
8  *  any later version.
9  *
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.
14  *
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/>.
18  *
19  */
20
21 #pragma once
22
23 #include "cores/playercorefactory/PlayerCoreFactory.h"
24
25 #include "ListItem.h"
26 #include "PlayList.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"
34
35 #include "swighelper.h"
36
37 namespace XBMCAddon
38 {
39   namespace xbmc
40   {
41     XBMCCOMMONS_STANDARD_EXCEPTION(PlayerException);
42
43     typedef Alternative<String, const PlayList* > PlayParameter;
44
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
48     //  this class.
49
50     /**
51      * Player class.
52      * 
53      * Player() -- Creates a new Player class.
54      */
55     class Player : public AddonCallback, public IPlayerCallback
56     {
57     private:
58       int iPlayList;
59       EPLAYERCORES playerCore;
60
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);
65
66     public:
67 #ifndef SWIG
68           static PlayParameter defaultPlayParameter;
69 #endif
70
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);
76
77       /**
78        * play([item, listitem, windowed]) -- Play this item.\n
79        * \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        * \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
86        * \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
89        * \n
90        * example:\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
94        */
95       void play(const PlayParameter& item = Player::defaultPlayParameter, 
96                 const XBMCAddon::xbmcgui::ListItem* listitem = NULL, bool windowed = false, int startpos = -1);
97
98       /**
99        * stop() -- Stop playing.
100        */
101       void stop();
102
103       /**
104        * pause() -- Pause playing.
105        */
106       void pause();
107
108       /**
109        * playnext() -- Play next item in playlist.
110        */
111       void playnext();
112
113       /**
114        * playprevious() -- Play previous item in playlist.
115        */
116       void playprevious();
117
118       /**
119        * playselected() -- Play a certain item from the current playlist.
120        */
121       void playselected(int selected);
122
123       /**
124        * onPlayBackStarted() -- onPlayBackStarted method.
125        * 
126        * Will be called when xbmc starts playing a file
127        */
128       // Player_OnPlayBackStarted
129       virtual void onPlayBackStarted();
130
131
132       /**
133        * onPlayBackEnded() -- onPlayBackEnded method.
134        * 
135        * Will be called when xbmc stops playing a file
136        */
137       // Player_OnPlayBackEnded
138       virtual void onPlayBackEnded();
139
140       /**
141        * onPlayBackStopped() -- onPlayBackStopped method.
142        * 
143        * Will be called when user stops xbmc playing a file
144        */
145       // Player_OnPlayBackStopped
146       virtual void onPlayBackStopped();
147
148       /**
149        * onPlayBackPaused() -- onPlayBackPaused method.
150        * 
151        * Will be called when user pauses a playing file
152        */
153       // Player_OnPlayBackPaused
154       virtual void onPlayBackPaused();
155
156       /**
157        * onPlayBackResumed() -- onPlayBackResumed method.
158        * 
159        * Will be called when user resumes a paused file
160        */
161       // Player_OnPlayBackResumed
162       virtual void onPlayBackResumed();
163
164       /**
165        * onQueueNextItem() -- onQueueNextItem method.
166        * 
167        * Will be called when user queues the next item
168        */
169       virtual void onQueueNextItem();
170
171       /**
172        * onPlayBackSpeedChanged(speed) -- onPlayBackSpeedChanged method.
173        * 
174        * speed          : integer - current speed of player.
175        * 
176        * *Note, negative speed means player is rewinding, 1 is normal playback speed.
177        * 
178        * Will be called when players speed changes. (eg. user FF/RW)
179        */
180       virtual void onPlayBackSpeedChanged(int speed);
181
182       /**
183        * onPlayBackSeek(time, seekOffset) -- onPlayBackSeek method.
184        * 
185        * time           : integer - time to seek to.\n
186        * seekOffset     : integer - ?.
187        * 
188        * Will be called when user seeks to a time
189        */
190       virtual void onPlayBackSeek(int time, int seekOffset);
191
192       /**
193        * onPlayBackSeekChapter(chapter) -- onPlayBackSeekChapter method.
194        * 
195        * chapter        : integer - chapter to seek to.
196        * 
197        * Will be called when user performs a chapter seek
198        */
199       virtual void onPlayBackSeekChapter(int chapter);
200
201       /**
202        * isPlaying() -- returns True is xbmc is playing a file.
203        */
204       // Player_IsPlaying
205       bool isPlaying();
206
207       /**
208        * isPlayingAudio() -- returns True is xbmc is playing an audio file.
209        */
210       // Player_IsPlayingAudio
211       bool isPlayingAudio();
212
213       /**
214        * isPlayingVideo() -- returns True if xbmc is playing a video.
215        */
216       // Player_IsPlayingVideo
217       bool isPlayingVideo();
218
219       /**
220        * getPlayingFile() -- returns the current playing file as a string.
221        * 
222        * Throws: Exception, if player is not playing a file.
223        */
224       // Player_GetPlayingFile
225       String getPlayingFile() throw (PlayerException);
226
227       /**
228        * getTime() -- Returns the current time of the current playing media as fractional seconds.
229        * 
230        * Throws: Exception, if player is not playing a file.
231        */
232       // Player_GetTime
233       double getTime() throw(PlayerException);
234
235       /**
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.
239        * 
240        * Throws: Exception, if player is not playing a file.
241        */
242       // Player_SeekTime
243       void seekTime(double seekTime) throw(PlayerException);
244
245       /**
246        * setSubtitles() -- set subtitle file and enable subtitlesn
247        */
248       // Player_SetSubtitles
249       void setSubtitles(const char* subtitleFile);
250
251       // Player_ShowSubtitles
252       /**
253        * showSubtitles(visible) -- enable/disable subtitles
254        * 
255        * visible        : boolean - True for visible subtitles.
256        *
257        * example:
258        * - xbmc.Player().showSubtitles(True)
259        */
260       void showSubtitles(bool bVisible);
261
262       /**
263        * getSubtitles() -- get subtitle stream name
264        */
265       // Player_GetSubtitles
266       String getSubtitles();
267
268       /**
269        * DisableSubtitles() -- disable subtitles
270        */
271       // Player_DisableSubtitles
272       void disableSubtitles();
273
274       // Player_getAvailableSubtitleStreams
275       /**
276        * getAvailableSubtitleStreams() -- get Subtitle stream names
277        */
278       std::vector<String>* getAvailableSubtitleStreams();
279
280       // Player_setSubtitleStream
281       /**
282        * setSubtitleStream(stream) -- set Subtitle Stream 
283        * 
284        * stream           : int
285        * 
286        * example:
287        *   - setSubtitleStream(1)
288        */
289       void setSubtitleStream(int iStream);
290
291       /**
292        * getVideoInfoTag() -- returns the VideoInfoTag of the current playing Movie.
293        * 
294        * Throws: Exception, if player is not playing a file or current file is not a movie file.
295        */
296       InfoTagVideo* getVideoInfoTag() throw (PlayerException);
297
298       /**
299        * getMusicInfoTag() -- returns the MusicInfoTag of the current playing 'Song'.
300        * 
301        * Throws: Exception, if player is not playing a file or current file is not a music file.
302        */
303       // Player_GetMusicInfoTag
304       InfoTagMusic* getMusicInfoTag() throw (PlayerException);
305
306       /**
307        *getTotalTime() -- Returns the total time of the current playing media in
308        *                  seconds.  This is only accurate to the full second.
309        *
310        *Throws: Exception, if player is not playing a file.
311        */
312       double getTotalTime() throw (PlayerException);
313
314       // Player_getAvailableAudioStreams
315       /**
316        * getAvailableAudioStreams() -- get Audio stream names
317        */
318       std::vector<String>* getAvailableAudioStreams();
319
320       /**
321        * setAudioStream(stream) -- set Audio Stream.
322        * 
323        * stream           : int
324        * 
325        * example:
326        * 
327        *    - setAudioStream(1)
328        */
329       void setAudioStream(int iStream);
330
331 #ifndef SWIG
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);
341 #endif
342
343     protected:
344     };
345   }
346 }
347