Parcourir la source

Improve the VideoSource

customisations
alemart il y a 1 an
Parent
révision
37b0c2fbc2
1 fichiers modifiés avec 16 ajouts et 13 suppressions
  1. 16
    13
      src/sources/video-source.ts

+ 16
- 13
src/sources/video-source.ts Voir le fichier

@@ -100,10 +100,16 @@ export class VideoSource implements Source
100 100
      */
101 101
     _init(): SpeedyPromise<void>
102 102
     {
103
-        return Speedy.load(this._video).then(media => {
104
-            Utils.log(`Source of data is a ${media.width}x${media.height} ${this._type}`);
105
-            this._media = media;
106
-            return this._handleBrowserQuirks(this._video).then(() => void(0));
103
+        Utils.log(`Initializing ${this._type} source...`);
104
+
105
+        // prepare the video before loading the SpeedyMedia!
106
+        return this._prepareVideo(this._video).then(video => {
107
+            Utils.log('The video is prepared');
108
+
109
+            return Speedy.load(video).then(media => {
110
+                Utils.log(`Source of data is a ${media.width}x${media.height} ${this._type}`);
111
+                this._media = media;
112
+            });
107 113
         });
108 114
     }
109 115
 
@@ -125,9 +131,8 @@ export class VideoSource implements Source
125 131
      * Handle browser-specific quirks for <video> elements
126 132
      * @param video a video element
127 133
      * @returns a promise that resolves to the input video
128
-     * @internal
129 134
      */
130
-    _handleBrowserQuirks(video: HTMLVideoElement): SpeedyPromise<HTMLVideoElement>
135
+    private _prepareVideo(video: HTMLVideoElement): SpeedyPromise<HTMLVideoElement>
131 136
     {
132 137
         // WebKit <video> policies for iOS:
133 138
         // https://webkit.org/blog/6784/new-video-policies-for-ios/
@@ -139,10 +144,10 @@ export class VideoSource implements Source
139 144
         return this._handleAutoPlay(video).then(video => {
140 145
 
141 146
             // handle WebKit quirks
142
-            // note: navigator.vendor is deprecated. Alternatively, test GL_RENDERER == "Apple GPU"
143
-            if(Utils.isIOS() || /Apple/.test(navigator.vendor)) {
147
+            if(Utils.isWebKit()) {
144 148
 
145 149
                 // on Epiphany, a hidden <video> shows up as a black screen when copied to a canvas
150
+                // on iOS, this hack doesn't seem necessary, but works okay
146 151
                 if(video.hidden) {
147 152
                     video.hidden = false;
148 153
                     video.style.setProperty('opacity', '0');
@@ -163,9 +168,8 @@ export class VideoSource implements Source
163 168
      * Handle browser-specific quirks for videos marked with autoplay
164 169
      * @param video a <video> marked with autoplay
165 170
      * @returns a promise that resolves to the input video
166
-     * @internal
167 171
      */
168
-    _handleAutoPlay(video: HTMLVideoElement): SpeedyPromise<HTMLVideoElement>
172
+    private _handleAutoPlay(video: HTMLVideoElement): SpeedyPromise<HTMLVideoElement>
169 173
     {
170 174
         // Autoplay guide: https://developer.mozilla.org/en-US/docs/Web/Media/Autoplay_guide
171 175
         // Chrome policy: https://developer.chrome.com/blog/autoplay/
@@ -251,9 +255,8 @@ export class VideoSource implements Source
251 255
      * Wait for the input video to be playable
252 256
      * @param video
253 257
      * @returns a promise that resolves to the input video when it can be played through to the end
254
-     * @internal
255 258
      */
256
-    _waitUntilPlayable(video: HTMLVideoElement): SpeedyPromise<HTMLVideoElement>
259
+    private _waitUntilPlayable(video: HTMLVideoElement): SpeedyPromise<HTMLVideoElement>
257 260
     {
258 261
         const TIMEOUT = 15000, INTERVAL = 500;
259 262
 
@@ -275,4 +278,4 @@ export class VideoSource implements Source
275 278
             }, INTERVAL);
276 279
         });
277 280
     }
278
-}
281
+}

Chargement…
Annuler
Enregistrer