@@ -31,6 +31,7 @@ define([
31
31
this . waveLayoutOptions ;
32
32
this . firstDrawing = true ;
33
33
this . latestRange ;
34
+ this . _plugins = [ ] ;
34
35
35
36
if ( options !== undefined ) {
36
37
@@ -70,8 +71,6 @@ define([
70
71
71
72
fps = count ;
72
73
73
- console . log ( 'fps: ' + fps ) ;
74
-
75
74
count = 1 ;
76
75
77
76
} else {
@@ -364,6 +363,38 @@ define([
364
363
this . waveLayoutOptions = layoutOptions ;
365
364
366
365
} ;
366
+
367
+ function callPlugin ( method , datas , breakValue ) {
368
+
369
+ for ( var i = 0 , len = this . _plugins . length ; i < len ; ++ i ) {
370
+
371
+ if ( ! ( method in this . _plugins [ i ] ) ) {
372
+
373
+ continue ;
374
+
375
+ }
376
+
377
+ var returnValue = this . _plugins [ i ] [ method ] . apply ( this , datas ) ;
378
+
379
+ if ( breakValue !== undefined && returnValue === breakValue ) {
380
+
381
+ return false ;
382
+
383
+ }
384
+
385
+ }
386
+
387
+ return true ;
388
+
389
+ }
390
+
391
+ waveform . prototype . addPlugin = function addPluginFunction ( plugin ) {
392
+
393
+ this . _plugins . push ( plugin ) ;
394
+
395
+ } ;
396
+
397
+ waveform . prototype . _plugins = null ;
367
398
368
399
var drawStop = false ;
369
400
var frameHandle ;
@@ -378,11 +409,13 @@ define([
378
409
379
410
var that = this ;
380
411
381
- var frameHandle = requestFrame ( function ( ) {
412
+ frameHandle = requestFrame ( function ( ) {
382
413
383
414
if ( ! drawStop ) {
384
415
385
- that . events . once ( that . events . constants . progressEvent , function ( range ) {
416
+ that . events . once ( that . events . constants . progressEvent , function ( data ) {
417
+
418
+ var range = ( data . position / data . duration ) * 100 ;
386
419
387
420
// redraw wave with different color until song progress
388
421
that . draw ( range ) ;
@@ -436,16 +469,24 @@ define([
436
469
var that = this ;
437
470
438
471
// on play listen for progress
439
- this . events . on ( this . events . constants . playEvent , function ( ) {
472
+ this . events . on ( this . events . constants . playEvent , function waveformPlayerPlayListener ( isPlaying ) {
473
+
474
+ if ( isPlaying && callPlugin . call ( that , 'onPlay' , arguments , false ) ) {
440
475
441
- that . updateRangeStart ( ) ;
476
+ that . updateRangeStart ( ) ;
477
+
478
+ }
442
479
443
480
} ) ;
444
481
445
482
// on stop, stop listening for progress
446
- this . events . on ( this . events . constants . stopEvent , function ( ) {
483
+ this . events . on ( this . events . constants . stopEvent , function waveformPlayerStopListener ( isPlaying ) {
447
484
448
- that . updateRangeStop ( ) ;
485
+ if ( ! isPlaying ) {
486
+
487
+ that . updateRangeStop ( ) ;
488
+
489
+ }
449
490
450
491
} ) ;
451
492
0 commit comments