@@ -27,6 +27,7 @@ export class Video extends VideoBase {
2727 #autoplay: boolean ;
2828 #loop: boolean ;
2929 #textureView: android . view . TextureView ;
30+
3031 _isCustom : boolean = false ;
3132 _playing : boolean = false ;
3233 _timer : any ;
@@ -39,13 +40,22 @@ export class Video extends VideoBase {
3940 _readyState : number = 0 ;
4041 _videoWidth = 0 ;
4142 _videoHeight = 0 ;
43+ private static _didInit = false ;
4244 constructor ( ) {
4345 super ( ) ;
4446 try {
4547 java . lang . System . loadLibrary ( 'canvasnative' ) ;
4648 } catch ( ex ) { }
49+
50+
4751 //@ts -ignore
4852 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+
4959 const builder = new com . google . android . exoplayer2 . SimpleExoPlayer . Builder ( activity ) ;
5060 this . #player = builder . build ( ) ;
5161 const ref = new WeakRef ( this ) ;
@@ -93,7 +103,7 @@ export class Video extends VideoBase {
93103 //console.log('PlayerError', error);
94104 } ,
95105 onPlayerStateChanged : function ( playWhenReady , playbackState ) {
96- //console.log('onPlayerStateChanged', Date.now());
106+ // console.log('onPlayerStateChanged', Date.now(), playbackState , STATE_BUFFERING );
97107 // if (playbackState === STATE_READY) {
98108 // playerReady = true;
99109 // } else if (playbackState === STATE_ENDED) {
@@ -166,6 +176,11 @@ export class Video extends VideoBase {
166176 if ( typeof value === 'string' && value . startsWith ( '~/' ) ) {
167177 value = path . join ( knownFolders . currentApp ( ) . path , value . replace ( '~' , '' ) ) ;
168178 }
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+
169184 this . #player. addMediaItem ( com . google . android . exoplayer2 . MediaItem . fromUri ( android . net . Uri . parse ( value ) ) ) ;
170185 this . #player. prepare ( ) ;
171186 if ( this . #autoplay) {
@@ -184,15 +199,15 @@ export class Video extends VideoBase {
184199 const st = surfaceView . getSurfaceTexture ( ) ;
185200 if ( st ) {
186201 // @ts -ignore
187- this . _render = com . github . triniwiz . canvas . Utils . createRenderAndAttachToGLContext ( context , st ) ;
202+ this . _render = org . nativescript . canvas . Utils . createRenderAndAttachToGLContext ( context , st ) ;
188203 this . _st = st ;
189204 }
190205 }
191206 }
192207
193208 if ( ! this . _st ) {
194209 // @ts -ignore
195- const result = com . github . triniwiz . canvas . Utils . createSurfaceTexture ( context ) ;
210+ const result = org . nativescript . canvas . Utils . createSurfaceTexture ( context ) ;
196211 this . _st = result [ 0 ] ;
197212 const ref = new WeakRef ( this ) ;
198213 this . _frameListener = new android . graphics . SurfaceTexture . OnFrameAvailableListener ( {
@@ -217,7 +232,7 @@ export class Video extends VideoBase {
217232 return ;
218233 }
219234 // @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 ] ) ;
221236 this . _hasFrame = false ;
222237 }
223238 }
0 commit comments