1
- import { Observable } from "data/observable" ;
2
- import { Page } from "ui/page" ;
3
- import { isAndroid } from "platform" ;
4
- import { setInterval } from "timer" ;
1
+ import { Observable } from "tns-core-modules/data/observable" ;
2
+ import { Page } from "tns-core-modules/ui/page" ;
3
+ import { topmost } from "tns-core-modules/ui/frame" ;
4
+ import { isAndroid } from "tns-core-modules/platform" ;
5
+ import { setInterval } from "tns-core-modules/timer" ;
6
+ import { StackLayout } from "tns-core-modules/ui/layouts/stack-layout" ;
5
7
import { Video } from "nativescript-videoplayer" ;
6
8
7
9
export class HelloWorldModel extends Observable {
@@ -36,7 +38,6 @@ export class HelloWorldModel extends Observable {
36
38
this . _videoPlayer . pause ( ) ;
37
39
}
38
40
39
-
40
41
/**
41
42
* Play the video
42
43
*/
@@ -45,7 +46,6 @@ export class HelloWorldModel extends Observable {
45
46
this . completed = false ;
46
47
}
47
48
48
-
49
49
/**
50
50
* Stop the video player
51
51
*/
@@ -55,7 +55,6 @@ export class HelloWorldModel extends Observable {
55
55
}
56
56
}
57
57
58
-
59
58
/**
60
59
* Get the video duration
61
60
*/
@@ -65,7 +64,6 @@ export class HelloWorldModel extends Observable {
65
64
this . set ( "videoDuration" , videoDuration ) ;
66
65
}
67
66
68
-
69
67
/**
70
68
* Go to 30 seconds
71
69
*/
@@ -77,43 +75,55 @@ export class HelloWorldModel extends Observable {
77
75
}
78
76
}
79
77
80
-
81
78
public animate ( ) {
82
79
console . log ( "Animation" ) ;
83
80
84
81
const enums = require ( "ui/enums" ) ;
85
- this . _videoPlayer . animate ( {
86
- rotate : 360 ,
87
- duration : 3000 ,
88
- curve : enums . AnimationCurve . spring
89
- } ) . then ( ( ) => {
90
- return this . _videoPlayer . animate ( {
91
- rotate : 0 ,
92
- duration : 3000 ,
93
- curve : enums . AnimationCurve . spring
94
- } ) ;
95
- } ) . then ( ( ) => {
96
- return this . _videoPlayer . animate ( {
97
- scale : { x : .5 , y : .5 } ,
98
- duration : 1000 ,
99
- curve : enums . AnimationCurve . spring
100
- } ) ;
101
-
102
- } ) . then ( ( ) => {
103
- return this . _videoPlayer . animate ( {
104
- scale : { x : 1.5 , y : 1.5 } ,
105
- duration : 3000 ,
106
- curve : enums . AnimationCurve . spring
107
- } ) ;
108
- } ) . then ( ( ) => {
109
- return this . _videoPlayer . animate ( {
110
- scale : { x : 1.0 , y : 1.0 } ,
82
+ this . _videoPlayer
83
+ . animate ( {
84
+ rotate : 360 ,
111
85
duration : 3000 ,
112
86
curve : enums . AnimationCurve . spring
87
+ } )
88
+ . then ( ( ) => {
89
+ return this . _videoPlayer . animate ( {
90
+ rotate : 0 ,
91
+ duration : 3000 ,
92
+ curve : enums . AnimationCurve . spring
93
+ } ) ;
94
+ } )
95
+ . then ( ( ) => {
96
+ return this . _videoPlayer . animate ( {
97
+ scale : { x : 0.5 , y : 0.5 } ,
98
+ duration : 1000 ,
99
+ curve : enums . AnimationCurve . spring
100
+ } ) ;
101
+ } )
102
+ . then ( ( ) => {
103
+ return this . _videoPlayer . animate ( {
104
+ scale : { x : 1.5 , y : 1.5 } ,
105
+ duration : 3000 ,
106
+ curve : enums . AnimationCurve . spring
107
+ } ) ;
108
+ } )
109
+ . then ( ( ) => {
110
+ return this . _videoPlayer . animate ( {
111
+ scale : { x : 1.0 , y : 1.0 } ,
112
+ duration : 3000 ,
113
+ curve : enums . AnimationCurve . spring
114
+ } ) ;
113
115
} ) ;
116
+ }
114
117
115
- } ) ;
116
-
118
+ public createVideoPlayer ( ) {
119
+ const video = new Video ( ) ;
120
+ video . height = 200 ;
121
+ video . width = 175 ;
122
+ video . src = "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" ;
123
+ video . controls = false ;
124
+ video . autoplay = true ;
125
+ const stack = topmost ( ) . getViewById ( "emptyStack" ) as StackLayout ;
126
+ stack . addChild ( video ) ;
117
127
}
118
128
119
129
public muteVideo ( ) {
@@ -124,7 +134,6 @@ export class HelloWorldModel extends Observable {
124
134
this . _videoPlayer . mute ( false ) ;
125
135
}
126
136
127
-
128
137
/**
129
138
* Get the video current time
130
139
*/
@@ -137,21 +146,18 @@ export class HelloWorldModel extends Observable {
137
146
}
138
147
}
139
148
140
-
141
-
142
149
/**
143
150
* Change the video src property
144
151
*/
145
152
public changeVideoSource ( ) {
146
153
if ( this . videoSrc === "~/videos/small.mp4" ) {
147
- this . _videoPlayer . src = "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" ;
154
+ this . _videoPlayer . src =
155
+ "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" ;
148
156
} else {
149
157
this . _videoPlayer . src = "~/videos/small.mp4" ;
150
158
}
151
159
}
152
160
153
-
154
-
155
161
private trackVideoCurrentPosition ( ) : number {
156
162
let trackInterval = setInterval ( ( ) => {
157
163
let x , y ;
@@ -166,8 +172,5 @@ export class HelloWorldModel extends Observable {
166
172
this . set ( "videoDuration" , y ) ;
167
173
} , 200 ) ;
168
174
return trackInterval ;
169
-
170
175
}
171
-
172
-
173
- }
176
+ }
0 commit comments