@@ -100,6 +100,13 @@ Object.assign(MediaElementPlayer.prototype, {
100100 radios = player . speedButton . querySelectorAll ( 'input[type="radio"]' ) ,
101101 labels = player . speedButton . querySelectorAll ( '.' + t . options . classPrefix + 'speed-selector-label' ) ;
102102
103+ /**
104+ * Store a reference to the radio buttons to prevent a scope bug in keyboard events
105+ * with multiple MediaElement players are on the same page. Otherwise these keyboard
106+ * events would always control the first speed button instance on the page.
107+ */
108+ player . speedRadioButtons = radios ;
109+
103110 for ( var _i2 = 0 , _total2 = inEvents . length ; _i2 < _total2 ; _i2 ++ ) {
104111 player . speedButton . addEventListener ( inEvents [ _i2 ] , function ( ) {
105112 mejs . Utils . removeClass ( player . speedSelector , t . options . classPrefix + 'offscreen' ) ;
@@ -154,9 +161,10 @@ Object.assign(MediaElementPlayer.prototype, {
154161 action : function action ( player , media , key , event ) {
155162 if ( event . key != '<' ) return ;
156163
157- for ( var _i7 = 0 ; _i7 < radios . length - 1 ; _i7 ++ ) {
158- if ( radios [ _i7 ] . checked ) {
159- var nextRadio = radios [ _i7 + 1 ] ;
164+ const _radios = player . speedRadioButtons ;
165+ for ( var _i7 = 0 ; _i7 < _radios . length - 1 ; _i7 ++ ) {
166+ if ( _radios [ _i7 ] . checked ) {
167+ var nextRadio = _radios [ _i7 + 1 ] ;
160168 nextRadio . dispatchEvent ( mejs . Utils . createEvent ( 'click' , nextRadio ) ) ;
161169 break ;
162170 }
@@ -167,9 +175,10 @@ Object.assign(MediaElementPlayer.prototype, {
167175 action : function action ( player , media , key , event ) {
168176 if ( event . key != '>' ) return ;
169177
170- for ( var _i8 = 1 ; _i8 < radios . length ; _i8 ++ ) {
171- if ( radios [ _i8 ] . checked ) {
172- var prevRadio = radios [ _i8 - 1 ] ;
178+ const _radios = player . speedRadioButtons ;
179+ for ( var _i8 = 1 ; _i8 < _radios . length ; _i8 ++ ) {
180+ if ( _radios [ _i8 ] . checked ) {
181+ var prevRadio = _radios [ _i8 - 1 ] ;
173182 prevRadio . dispatchEvent ( mejs . Utils . createEvent ( 'click' , prevRadio ) ) ;
174183 break ;
175184 }
0 commit comments