@@ -195,86 +195,38 @@ playerjs.Player.prototype.off = function(event, callback){
195
195
return false ;
196
196
} ;
197
197
198
- playerjs . Player . prototype . play = function ( ) {
199
- this . send ( {
200
- method : 'play'
201
- } ) ;
202
- } ;
203
-
204
- playerjs . Player . prototype . pause = function ( ) {
205
- this . send ( {
206
- method : 'pause'
207
- } ) ;
208
- } ;
209
-
210
- playerjs . Player . prototype . getPaused = function ( callback , ctx ) {
211
- this . send ( {
212
- method : 'getPaused'
213
- } , callback , ctx ) ;
214
- } ;
215
-
216
- playerjs . Player . prototype . mute = function ( ) {
217
- this . send ( {
218
- method : 'mute'
219
- } ) ;
220
- } ;
221
-
222
- playerjs . Player . prototype . unmute = function ( ) {
223
- this . send ( {
224
- method : 'unmute'
225
- } ) ;
226
- } ;
227
-
228
- playerjs . Player . prototype . getMuted = function ( callback , ctx ) {
229
- this . send ( {
230
- method : 'getMuted'
231
- } , callback , ctx ) ;
232
- } ;
233
-
234
- playerjs . Player . prototype . getVolume = function ( callback , ctx ) {
235
- this . send ( {
236
- method : 'getVolume'
237
- } , callback , ctx ) ;
238
- } ;
239
-
240
- playerjs . Player . prototype . setVolume = function ( value ) {
241
- this . send ( {
242
- method : 'setVolume' ,
243
- value : value
244
- } ) ;
245
- } ;
246
-
247
- playerjs . Player . prototype . getDuration = function ( callback , ctx ) {
248
- this . send ( {
249
- method : 'getDuration'
250
- } , callback , ctx ) ;
251
- } ;
198
+ for ( var i = 0 , l = playerjs . METHODS . length - 2 ; i < l ; i ++ ) {
199
+ var methodName = playerjs . METHODS [ i ] ;
200
+ playerjs . Player . prototype [ methodName ] = createPrototypeFunction ( methodName )
201
+ }
202
+
203
+ //create function to add to the Player prototype
204
+ function createPrototypeFunction ( name ) {
205
+ return function ( ) {
206
+ var data = {
207
+ method : name
208
+ } ;
209
+ var args = Array . prototype . slice . call ( arguments ) ;
210
+ var argsToCall ;
252
211
253
- playerjs . Player . prototype . setCurrentTime = function ( value ) {
254
- this . send ( {
255
- method : 'setCurrentTime' ,
256
- value : value
257
- } ) ;
258
- } ;
212
+ //for setter add the first arg to the value field
213
+ if ( / ^ s e t / . test ( name ) ) {
214
+ data . value = args [ 0 ]
215
+ }
259
216
260
- playerjs . Player . prototype . getCurrentTime = function ( callback , ctx ) {
261
- this . send ( {
262
- method : 'getCurrentTime'
263
- } , callback , ctx ) ;
264
- } ;
217
+ //for getters add the passed parameters to the arguments for the send call
218
+ if ( / ^ g e t / . test ( name ) ) {
219
+ args . unshift ( data ) ;
220
+ argsToCall = args ;
221
+ //otherwise only use the data object
222
+ } else {
223
+ argsToCall = [ data ] ;
224
+ }
265
225
266
- playerjs . Player . prototype . setLoop = function ( value ) {
267
- this . send ( {
268
- method : 'getLoop' ,
269
- value : value
270
- } ) ;
271
- } ;
226
+ this . send . apply ( this , argsToCall )
227
+ }
228
+ }
272
229
273
- playerjs . Player . prototype . getLoop = function ( callback , ctx ) {
274
- this . send ( {
275
- method : 'getLoop'
276
- } , callback , ctx ) ;
277
- } ;
278
230
279
231
window . playerjs = playerjs ;
280
232
0 commit comments