@@ -93,11 +93,60 @@ function showDivs(n) {
9393
9494document . onkeydown = function ( event ) {
9595 var kbpressed = event . key ;
96+ // tricky overrides browser shortcut keys
97+ //event.preventDefault();
98+ // todo harmonize with audio end
99+ if ( currentIndex == trElements . length ) {
100+ currentIndex = 0 ;
101+ }
102+ // audio previous
96103 if ( kbpressed == "ArrowLeft" ) {
97104 plusDivs ( - 1 ) ;
105+ // shuffle play
106+ //if (shuffle) {
107+ // currentIndex = previousPicks[currentIndex - 1];
108+ // audioplay(urls[currentIndex], trElements[currentIndex]);
109+ //} else {
110+ if ( currentIndex > 1 ) {
111+ audioplay ( urls [ currentIndex - 2 ] , trElements [ currentIndex - 2 ] ) ;
112+ }
113+ //}
98114 }
115+ // audio next
99116 if ( kbpressed == "ArrowRight" ) {
100117 plusDivs ( 1 ) ;
118+ // shuffle play
119+ if ( shuffle ) {
120+ currentIndex = shuffleplay ( trElements . length ) ;
121+ }
122+ audioplay ( urls [ currentIndex ] , trElements [ currentIndex ] ) ;
123+ }
124+ // audio pause / play
125+ if ( kbpressed == "p" ) {
126+ if ( document . getElementById ( "audio" ) . paused ) {
127+ document . getElementById ( "audio" ) . play ( ) ;
128+ } else {
129+ document . getElementById ( "audio" ) . pause ( ) ;
130+ }
131+ }
132+ // audio seek
133+ if ( kbpressed == "." ) {
134+ document . getElementById ( "audio" ) . currentTime = document . getElementById ( "audio" ) . currentTime + 5 ;
135+ }
136+ if ( kbpressed == "," ) {
137+ document . getElementById ( "audio" ) . currentTime = document . getElementById ( "audio" ) . currentTime - 5 ;
138+ }
139+ // audio volume
140+ if ( kbpressed == "+" ) {
141+ console . log ( document . getElementById ( "audio" ) . volume ) ;
142+ if ( document . getElementById ( "audio" ) . volume < 0.9 ) {
143+ document . getElementById ( "audio" ) . volume = document . getElementById ( "audio" ) . volume + 0.1 ;
144+ }
145+ }
146+ if ( kbpressed == "-" ) {
147+ if ( document . getElementById ( "audio" ) . volume >= 0.1 ) {
148+ document . getElementById ( "audio" ) . volume = document . getElementById ( "audio" ) . volume - 0.1 ;
149+ }
101150 }
102151 if ( kbpressed == "Escape" ) {
103152 if ( modal . style == undefined ) {
@@ -109,21 +158,22 @@ document.onkeydown = function (event) {
109158
110159// play audio source
111160function audioplay ( music , element ) {
161+ currentIndex = element . closest ( 'tr' ) . rowIndex - 1 ;
162+ //console.log(currentIndex);
163+ console . log ( 'Playing:' , titles [ element . closest ( 'tr' ) . rowIndex - 1 ] ) ;
112164 document . getElementById ( "audio" ) . pause ( ) ;
113165 document . getElementById ( "audio" ) . setAttribute ( 'src' , music ) ;
114166 document . getElementById ( "audio" ) . setAttribute ( 'type' , 'audio/mpeg' ) ;
115167 document . getElementById ( "audio" ) . load ( ) ;
116168 document . getElementById ( "audio" ) . play ( ) ;
117- document . getElementById ( "audio" ) . volume = 0.5 ;
169+ // document.getElementById("audio").volume = 0.5;
118170 document . getElementById ( "audio" ) . style . visibility = "visible" ;
119171 // set or remove play button
120172 var data = document . getElementsByClassName ( "audiobutton" ) ;
121- // reset selected up and down
122173 for ( i = 0 ; i < data . length ; i ++ ) {
123174 data [ i ] . style . visibility = "hidden" ;
124175 }
125176 for ( i = 0 ; i < data . length ; i ++ ) {
126- // toggle on row id
127177 if ( i == element . closest ( 'tr' ) . rowIndex - 1 ) {
128178 data [ i ] . style . visibility = "visible" ;
129179 }
@@ -132,6 +182,8 @@ function audioplay(music, element) {
132182 for ( i = 0 ; i < data . length ; i ++ ) {
133183 data [ i ] . style . visibility = "visible" ;
134184 }
185+
186+ currentIndex ++ ;
135187}
136188
137189// play youtube audio source
0 commit comments