@@ -13,6 +13,7 @@ import {assign} from '../utils/obj';
1313import mergeOptions from '../utils/merge-options.js' ;
1414import toTitleCase from '../utils/to-title-case.js' ;
1515import { NORMAL as TRACK_TYPES } from '../tracks/track-types' ;
16+ import setupSourceset from './setup-sourceset' ;
1617
1718/**
1819 * HTML5 Media Controller - Wrapper for HTML5 Media API
@@ -128,84 +129,7 @@ class Html5 extends Tech {
128129 * the source is changed. Fires `sourceset` just after the source has changed
129130 */
130131 setupSourcesetHandling_ ( ) {
131- if ( ! this . featuresSourceset ) {
132- return ;
133- }
134-
135- const el = this . el ( ) ;
136-
137- // we need to fire sourceset when the player is ready
138- // if we find that the media element had a src when it was
139- // given to us and that tech element is not in a stalled state
140- if ( el . src || el . currentSrc && this . el ( ) . initNetworkState_ !== 3 ) {
141- this . triggerSourceset ( el . src || el . currentSrc ) ;
142- }
143-
144- const proto = window . HTMLMediaElement . prototype ;
145- let srcDescriptor = { } ;
146-
147- // preserve getters/setters already on `el.src` if they exist
148- if ( Object . getOwnPropertyDescriptor ( el , 'src' ) ) {
149- srcDescriptor = Object . getOwnPropertyDescriptor ( el , 'src' ) ;
150- } else if ( Object . getOwnPropertyDescriptor ( proto , 'src' ) ) {
151- srcDescriptor = mergeOptions ( srcDescriptor , Object . getOwnPropertyDescriptor ( proto , 'src' ) ) ;
152- }
153-
154- if ( ! srcDescriptor . get ) {
155- srcDescriptor . get = function ( ) {
156- return proto . getAttribute . call ( this , 'src' ) ;
157- } ;
158- }
159-
160- if ( ! srcDescriptor . set ) {
161- srcDescriptor . set = function ( v ) {
162- return proto . setAttribute . call ( this , 'src' , v ) ;
163- } ;
164- }
165-
166- if ( typeof srcDescriptor . enumerable === 'undefined' ) {
167- srcDescriptor . enumerable = true ;
168- }
169-
170- Object . defineProperty ( el , 'src' , {
171- get : srcDescriptor . get . bind ( el ) ,
172- set : ( v ) => {
173- const retval = srcDescriptor . set . call ( el , v ) ;
174-
175- this . triggerSourceset ( v ) ;
176-
177- return retval ;
178- } ,
179- configurable : true ,
180- enumerable : srcDescriptor . enumerable
181- } ) ;
182-
183- const oldSetAttribute = el . setAttribute ;
184-
185- el . setAttribute = ( n , v ) => {
186- const retval = oldSetAttribute . call ( el , n , v ) ;
187-
188- if ( n === 'src' ) {
189- this . triggerSourceset ( v ) ;
190- }
191-
192- return retval ;
193- } ;
194-
195- const oldLoad = el . load ;
196-
197- el . load = ( ) => {
198- const retval = oldLoad . call ( el ) ;
199-
200- // if `el.src` is set, that source will be loaded
201- // otherwise, we can't know for sure what source will be set because
202- // source elements will be used but implementing the source selection algorithm
203- // is laborious and asynchronous, so,
204- // instead return an empty string to basically indicate source may change
205- this . triggerSourceset ( el . src || '' ) ;
206-
207- return retval ;
208- } ;
132+ setupSourceset ( this ) ;
209133 }
210134
211135 /**
0 commit comments