@@ -27,6 +27,7 @@ export class Video extends VideoBase {
27
27
#autoplay: boolean ;
28
28
#loop: boolean ;
29
29
#textureView: android . view . TextureView ;
30
+
30
31
_isCustom : boolean = false ;
31
32
_playing : boolean = false ;
32
33
_timer : any ;
@@ -39,13 +40,22 @@ export class Video extends VideoBase {
39
40
_readyState : number = 0 ;
40
41
_videoWidth = 0 ;
41
42
_videoHeight = 0 ;
43
+ private static _didInit = false ;
42
44
constructor ( ) {
43
45
super ( ) ;
44
46
try {
45
47
java . lang . System . loadLibrary ( 'canvasnative' ) ;
46
48
} catch ( ex ) { }
49
+
50
+
47
51
//@ts -ignore
48
52
const activity : androidx . appcompat . app . AppCompatActivity = Application . android . foregroundActivity || Application . android . startActivity ;
53
+
54
+ if ( ! Video . _didInit ) {
55
+ // @ts -ignore
56
+ org . nativescript . canvas_media . Utils . init ( activity , path . join ( knownFolders . documents ( ) . path , 'MEDIA_PLAYER_CACHE' ) ) ;
57
+ }
58
+
49
59
const builder = new com . google . android . exoplayer2 . SimpleExoPlayer . Builder ( activity ) ;
50
60
this . #player = builder . build ( ) ;
51
61
const ref = new WeakRef ( this ) ;
@@ -93,7 +103,7 @@ export class Video extends VideoBase {
93
103
//console.log('PlayerError', error);
94
104
} ,
95
105
onPlayerStateChanged : function ( playWhenReady , playbackState ) {
96
- //console.log('onPlayerStateChanged', Date.now());
106
+ // console.log('onPlayerStateChanged', Date.now(), playbackState , STATE_BUFFERING );
97
107
// if (playbackState === STATE_READY) {
98
108
// playerReady = true;
99
109
// } else if (playbackState === STATE_ENDED) {
@@ -166,6 +176,11 @@ export class Video extends VideoBase {
166
176
if ( typeof value === 'string' && value . startsWith ( '~/' ) ) {
167
177
value = path . join ( knownFolders . currentApp ( ) . path , value . replace ( '~' , '' ) ) ;
168
178
}
179
+ if ( typeof value === 'string' && value . startsWith ( 'http' ) ) {
180
+ // @ts -ignore
181
+ org . nativescript . canvas_media . Utils . cacheUrl ( Application . android . foregroundActivity || Application . android . startActivity , value ) ;
182
+ }
183
+
169
184
this . #player. addMediaItem ( com . google . android . exoplayer2 . MediaItem . fromUri ( android . net . Uri . parse ( value ) ) ) ;
170
185
this . #player. prepare ( ) ;
171
186
if ( this . #autoplay) {
@@ -184,15 +199,15 @@ export class Video extends VideoBase {
184
199
const st = surfaceView . getSurfaceTexture ( ) ;
185
200
if ( st ) {
186
201
// @ts -ignore
187
- this . _render = com . github . triniwiz . canvas . Utils . createRenderAndAttachToGLContext ( context , st ) ;
202
+ this . _render = org . nativescript . canvas . Utils . createRenderAndAttachToGLContext ( context , st ) ;
188
203
this . _st = st ;
189
204
}
190
205
}
191
206
}
192
207
193
208
if ( ! this . _st ) {
194
209
// @ts -ignore
195
- const result = com . github . triniwiz . canvas . Utils . createSurfaceTexture ( context ) ;
210
+ const result = org . nativescript . canvas . Utils . createSurfaceTexture ( context ) ;
196
211
this . _st = result [ 0 ] ;
197
212
const ref = new WeakRef ( this ) ;
198
213
this . _frameListener = new android . graphics . SurfaceTexture . OnFrameAvailableListener ( {
@@ -217,7 +232,7 @@ export class Video extends VideoBase {
217
232
return ;
218
233
}
219
234
// @ts -ignore
220
- com . github . triniwiz . canvas . Utils . updateTexImage ( context , this . _st , this . _render , this . _videoWidth , this . _videoHeight , arguments [ 4 ] , arguments [ 5 ] ) ;
235
+ org . nativescript . canvas . Utils . updateTexImage ( context , this . _st , this . _render , this . _videoWidth , this . _videoHeight , arguments [ 4 ] , arguments [ 5 ] ) ;
221
236
this . _hasFrame = false ;
222
237
}
223
238
}
0 commit comments