11function CodeKeyframes ( args ) {
22
3- if ( ! args . audioPath ) return
3+ if ( ! args . audioPath && ! args . videoElement ) return
44
5- this . audioPath = args . audioPath
6- this . editorOpen = args . editorOpen || false
7- this . keyframes = args . keyframes || [ ]
8- this . label = args . label
9- this . autoplay = args . autoplay || false
10- this . state = args . state || { }
5+ this . audioPath = args . audioPath
6+ this . videoElement = args . videoElement
7+ this . editorOpen = args . editorOpen || false
8+ this . keyframes = args . keyframes || [ ]
9+ this . label = args . label
10+ this . autoplay = args . autoplay || false
11+ this . state = args . state || { }
1112
1213 // event callbacks
1314 this . onFrame = args . onFrame || function ( ) { }
@@ -61,10 +62,7 @@ function CodeKeyframes(args){
6162 this . _panel . appendChild ( _label )
6263 }
6364
64- // immediately close editor if needed
65- if ( ! this . editorOpen ) {
66- this . toggleEditor ( )
67- }
65+
6866
6967
7068 /*
@@ -549,6 +547,11 @@ function CodeKeyframes(args){
549547 this . editorOpen = ! this . editorOpen
550548 }
551549
550+ // immediately close editor if needed
551+ if ( ! this . editorOpen ) {
552+ this . toggleEditor ( )
553+ }
554+
552555 this . updateStatePanel = ( regionState ) => {
553556
554557 // default to initial state
@@ -594,6 +597,9 @@ function CodeKeyframes(args){
594597 var waveColor = args . waveColor || '#3AEAD2'
595598 var progressColor = args . progressColor || '#0c9fa7'
596599
600+ var backend = 'WebAudio'
601+ if ( this . videoElement ) backend = "MediaElement"
602+
597603 this . wavesurfer = WaveSurfer . create ( {
598604 container : '.ckf-waveform' ,
599605 height : waveHeight ,
@@ -603,10 +609,15 @@ function CodeKeyframes(args){
603609 progressColor : progressColor ,
604610 barWidth : 1 ,
605611 cursorColor : '#fff' ,
606- plugins : [ WaveSurfer . cursor . create ( ) , WaveSurfer . regions . create ( ) ]
612+ backend : backend ,
613+ plugins : [ WaveSurfer . cursor . create ( ) , WaveSurfer . regions . create ( ) ]
607614 } )
608615
609- this . wavesurfer . load ( this . audioPath )
616+ if ( this . videoElement ) {
617+ this . wavesurfer . load ( this . videoElement )
618+ } else {
619+ this . wavesurfer . load ( this . audioPath )
620+ }
610621
611622 // run function passed to codekeyframes on init
612623 this . wavesurfer . on ( 'pause' , ( ) => {
0 commit comments