@nativescript/canvas-media 2.0.11 → 2.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/VideoFrame/common.d.ts +122 -0
- package/VideoFrame/common.js +173 -0
- package/VideoFrame/common.js.map +1 -0
- package/VideoFrame/index.android.d.ts +12 -0
- package/VideoFrame/index.android.js +113 -0
- package/VideoFrame/index.android.js.map +1 -0
- package/VideoFrame/index.ios.d.ts +12 -0
- package/VideoFrame/index.ios.js +122 -0
- package/VideoFrame/index.ios.js.map +1 -0
- package/audio/common.d.ts +29 -3
- package/audio/common.js +90 -0
- package/audio/common.js.map +1 -1
- package/audio/index.android.d.ts +32 -1
- package/audio/index.android.js +219 -1
- package/audio/index.android.js.map +1 -1
- package/audio/index.ios.d.ts +27 -4
- package/audio/index.ios.js +183 -142
- package/audio/index.ios.js.map +1 -1
- package/common.d.ts +1 -0
- package/common.js +3 -0
- package/common.js.map +1 -1
- package/index.d.ts +2 -0
- package/index.js +1 -0
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/platforms/android/canvas_media.aar +0 -0
- package/platforms/android/java/org/nativescript/canvas/media/AudioHelper.java +338 -0
- package/platforms/android/java/org/nativescript/canvas/media/AudioView.java +125 -0
- package/platforms/android/java/org/nativescript/canvas/media/SimpleCacheProvider.java +27 -0
- package/platforms/android/java/org/nativescript/canvas/media/VideoHelper.java +204 -5
- package/platforms/ios/src/NSCAudioHelper.h +47 -0
- package/platforms/ios/src/NSCAudioHelper.m +713 -0
- package/platforms/ios/src/NSCAudioView.h +20 -0
- package/platforms/ios/src/NSCAudioView.m +270 -0
- package/platforms/ios/src/NSCCanvasMediaUmbrella.h +3 -1
- package/platforms/ios/src/NSCVideoHelper.h +6 -0
- package/platforms/ios/src/NSCVideoHelper.m +111 -4
- package/video/common.d.ts +4 -0
- package/video/common.js +3 -0
- package/video/common.js.map +1 -1
- package/video/index.android.d.ts +3 -1
- package/video/index.android.js +44 -8
- package/video/index.android.js.map +1 -1
- package/video/index.ios.d.ts +2 -0
- package/video/index.ios.js +28 -0
- package/video/index.ios.js.map +1 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//
|
|
2
|
+
// NSCAudioView.h
|
|
3
|
+
// CanvasMedia
|
|
4
|
+
//
|
|
5
|
+
#import <UIKit/UIKit.h>
|
|
6
|
+
|
|
7
|
+
@class NSCAudioHelper;
|
|
8
|
+
|
|
9
|
+
@interface NSCAudioView : UIView
|
|
10
|
+
|
|
11
|
+
- (instancetype)initWithHelper:(NSCAudioHelper *)helper;
|
|
12
|
+
- (void)updateCurrentTime:(double)seconds;
|
|
13
|
+
- (void)setPlaying:(BOOL)playing;
|
|
14
|
+
- (void)setDuration:(double)seconds;
|
|
15
|
+
|
|
16
|
+
- (void)setPlayImage:(UIImage *)image;
|
|
17
|
+
- (void)setPauseImage:(UIImage *)image;
|
|
18
|
+
- (void)setIconTintColor:(UIColor *)color;
|
|
19
|
+
|
|
20
|
+
@end
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
//
|
|
2
|
+
// NSCAudioView.m
|
|
3
|
+
// CanvasMedia
|
|
4
|
+
//
|
|
5
|
+
#import "NSCAudioView.h"
|
|
6
|
+
#import "NSCAudioHelper.h"
|
|
7
|
+
|
|
8
|
+
@implementation NSCAudioView {
|
|
9
|
+
__weak NSCAudioHelper *_helper;
|
|
10
|
+
UIButton *_playButton;
|
|
11
|
+
UISlider *_slider;
|
|
12
|
+
UILabel *_timeLabel;
|
|
13
|
+
BOOL _isSeeking;
|
|
14
|
+
UIImage *_customPlayImage;
|
|
15
|
+
UIImage *_customPauseImage;
|
|
16
|
+
UIColor *_iconTintColor;
|
|
17
|
+
double _durationSeconds;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
- (instancetype)initWithHelper:(NSCAudioHelper *)helper {
|
|
21
|
+
if (self = [super initWithFrame:CGRectZero]) {
|
|
22
|
+
_helper = helper;
|
|
23
|
+
self.backgroundColor = [UIColor clearColor];
|
|
24
|
+
self.translatesAutoresizingMaskIntoConstraints = NO;
|
|
25
|
+
|
|
26
|
+
_playButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
27
|
+
_playButton.translatesAutoresizingMaskIntoConstraints = YES;
|
|
28
|
+
UIImage *playImage = nil;
|
|
29
|
+
if (@available(iOS 13.0, *)) {
|
|
30
|
+
playImage = [UIImage systemImageNamed:@"play.fill"];
|
|
31
|
+
_playButton.tintColor = [UIColor systemBlueColor];
|
|
32
|
+
}
|
|
33
|
+
if (!playImage) {
|
|
34
|
+
playImage = [self _playIconWithSize:CGSizeMake(40,40) color:[UIColor blackColor]];
|
|
35
|
+
_playButton.tintColor = [UIColor blackColor];
|
|
36
|
+
}
|
|
37
|
+
if (playImage) {
|
|
38
|
+
[_playButton setImage:[playImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
|
|
39
|
+
}
|
|
40
|
+
[_playButton addTarget:self action:@selector(playTapped:) forControlEvents:UIControlEventTouchUpInside];
|
|
41
|
+
[self addSubview:_playButton];
|
|
42
|
+
|
|
43
|
+
_slider = [[UISlider alloc] initWithFrame:CGRectZero];
|
|
44
|
+
_slider.translatesAutoresizingMaskIntoConstraints = YES;
|
|
45
|
+
_slider.enabled = NO;
|
|
46
|
+
[_slider addTarget:self action:@selector(sliderChanged:) forControlEvents:UIControlEventValueChanged];
|
|
47
|
+
[_slider addTarget:self action:@selector(sliderTouchDown:) forControlEvents:UIControlEventTouchDown];
|
|
48
|
+
[_slider addTarget:self action:@selector(sliderTouchUp:) forControlEvents:UIControlEventTouchUpInside | UIControlEventTouchUpOutside];
|
|
49
|
+
[self addSubview:_slider];
|
|
50
|
+
|
|
51
|
+
_timeLabel = [[UILabel alloc] initWithFrame:CGRectZero];
|
|
52
|
+
_timeLabel.translatesAutoresizingMaskIntoConstraints = YES;
|
|
53
|
+
_durationSeconds = 0.0;
|
|
54
|
+
_timeLabel.text = @"0:00 / 0:00";
|
|
55
|
+
_slider.minimumValue = 0;
|
|
56
|
+
_slider.maximumValue = 1.0f;
|
|
57
|
+
[self addSubview:_timeLabel];
|
|
58
|
+
}
|
|
59
|
+
return self;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
- (void)layoutSubviews {
|
|
63
|
+
[super layoutSubviews];
|
|
64
|
+
CGFloat pad = 8.0;
|
|
65
|
+
CGFloat w = CGRectGetWidth(self.bounds);
|
|
66
|
+
CGFloat h = CGRectGetHeight(self.bounds);
|
|
67
|
+
if (w <= 0 || h <= 0) return;
|
|
68
|
+
|
|
69
|
+
CGFloat btnW = 40.0;
|
|
70
|
+
CGFloat btnH = 40.0;
|
|
71
|
+
CGFloat btnY = floor((h - btnH) / 2.0);
|
|
72
|
+
_playButton.frame = CGRectMake(pad, btnY, btnW, btnH);
|
|
73
|
+
|
|
74
|
+
CGFloat maxLabelWidth = 120.0;
|
|
75
|
+
CGSize labelSize = [_timeLabel sizeThatFits:CGSizeMake(maxLabelWidth, h)];
|
|
76
|
+
CGFloat labelW = MIN(labelSize.width, maxLabelWidth);
|
|
77
|
+
CGFloat labelH = MIN(labelSize.height, h);
|
|
78
|
+
CGFloat labelX = w - pad - labelW;
|
|
79
|
+
CGFloat labelY = floor((h - labelH) / 2.0);
|
|
80
|
+
_timeLabel.frame = CGRectMake(labelX, labelY, labelW, labelH);
|
|
81
|
+
|
|
82
|
+
CGFloat sliderX = CGRectGetMaxX(_playButton.frame) + pad;
|
|
83
|
+
CGFloat sliderW = labelX - pad - sliderX;
|
|
84
|
+
if (sliderW < 40.0) sliderW = 40.0;
|
|
85
|
+
CGFloat sliderH = 30.0;
|
|
86
|
+
CGFloat sliderY = floor((h - sliderH) / 2.0);
|
|
87
|
+
_slider.frame = CGRectMake(sliderX, sliderY, sliderW, sliderH);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
- (void)playTapped:(id)sender {
|
|
91
|
+
if (!_helper) return;
|
|
92
|
+
if ([_helper state] == 1) {
|
|
93
|
+
[_helper pause];
|
|
94
|
+
} else {
|
|
95
|
+
[_helper play];
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
- (void)sliderChanged:(UISlider *)s {
|
|
100
|
+
if (!_isSeeking) return;
|
|
101
|
+
double seconds = s.value;
|
|
102
|
+
[self updateTimeLabelWithCurrent:seconds duration:_durationSeconds];
|
|
103
|
+
if (_helper) {
|
|
104
|
+
@try {
|
|
105
|
+
[_helper setCurrentTime:seconds];
|
|
106
|
+
} @catch (NSException *ex) {}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
- (void)sliderTouchDown:(UISlider *)s {
|
|
111
|
+
_isSeeking = YES;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
- (void)sliderTouchUp:(UISlider *)s {
|
|
115
|
+
_isSeeking = NO;
|
|
116
|
+
if (!_helper) return;
|
|
117
|
+
double seconds = s.value;
|
|
118
|
+
[_helper setCurrentTime:seconds];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
- (void)updateCurrentTime:(double)seconds {
|
|
122
|
+
if (_isSeeking) return;
|
|
123
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
124
|
+
self->_slider.value = seconds;
|
|
125
|
+
[self updateTimeLabelWithCurrent:seconds duration:self->_durationSeconds];
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
- (void)setPlaying:(BOOL)playing {
|
|
130
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
131
|
+
UIImage *img = nil;
|
|
132
|
+
if (playing ? _customPauseImage : _customPlayImage) {
|
|
133
|
+
img = playing ? _customPauseImage : _customPlayImage;
|
|
134
|
+
if (img) {
|
|
135
|
+
UIImage *templ = [img imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
|
|
136
|
+
[_playButton setImage:templ forState:UIControlStateNormal];
|
|
137
|
+
if (_iconTintColor) _playButton.tintColor = _iconTintColor;
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (@available(iOS 13.0, *)) {
|
|
143
|
+
img = [UIImage systemImageNamed:(playing ? @"pause.fill" : @"play.fill")];
|
|
144
|
+
if (img) {
|
|
145
|
+
UIImage *templ = [img imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
|
|
146
|
+
[_playButton setImage:templ forState:UIControlStateNormal];
|
|
147
|
+
if (_iconTintColor) _playButton.tintColor = _iconTintColor;
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
UIColor *c = _iconTintColor ?: [UIColor blackColor];
|
|
153
|
+
UIImage *fallback = playing ? [self _pauseIconWithSize:CGSizeMake(40,40) color:c] : [self _playIconWithSize:CGSizeMake(40,40) color:c];
|
|
154
|
+
if (fallback) {
|
|
155
|
+
[_playButton setImage:[fallback imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
|
|
156
|
+
if (_iconTintColor) _playButton.tintColor = _iconTintColor;
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
- (void)setPlayImage:(UIImage *)image {
|
|
162
|
+
_customPlayImage = image;
|
|
163
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
164
|
+
BOOL playing = NO;
|
|
165
|
+
if (_helper) {
|
|
166
|
+
playing = ([_helper state] == NSCPlayerStatePlaying);
|
|
167
|
+
}
|
|
168
|
+
if (!playing && _customPlayImage) {
|
|
169
|
+
UIImage *img = [_customPlayImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
|
|
170
|
+
[_playButton setImage:img forState:UIControlStateNormal];
|
|
171
|
+
if (_iconTintColor) _playButton.tintColor = _iconTintColor;
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
- (void)setPauseImage:(UIImage *)image {
|
|
177
|
+
_customPauseImage = image;
|
|
178
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
179
|
+
BOOL playing = NO;
|
|
180
|
+
if (_helper) {
|
|
181
|
+
playing = ([_helper state] == NSCPlayerStatePlaying);
|
|
182
|
+
}
|
|
183
|
+
if (playing && _customPauseImage) {
|
|
184
|
+
UIImage *img = [_customPauseImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
|
|
185
|
+
[_playButton setImage:img forState:UIControlStateNormal];
|
|
186
|
+
if (_iconTintColor) _playButton.tintColor = _iconTintColor;
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
- (void)setIconTintColor:(UIColor *)color {
|
|
192
|
+
_iconTintColor = color;
|
|
193
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
194
|
+
if (_iconTintColor) {
|
|
195
|
+
_playButton.tintColor = _iconTintColor;
|
|
196
|
+
}
|
|
197
|
+
BOOL playing = NO;
|
|
198
|
+
if (_helper) {
|
|
199
|
+
playing = ([_helper state] == NSCPlayerStatePlaying);
|
|
200
|
+
}
|
|
201
|
+
[self setPlaying:playing];
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
- (UIImage *)_playIconWithSize:(CGSize)size color:(UIColor *)color {
|
|
206
|
+
if (!color) color = [UIColor blackColor];
|
|
207
|
+
UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:size];
|
|
208
|
+
UIImage *img = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull ctx) {
|
|
209
|
+
CGContextRef context = ctx.CGContext;
|
|
210
|
+
CGContextSetFillColorWithColor(context, color.CGColor);
|
|
211
|
+
CGFloat w = size.width;
|
|
212
|
+
CGFloat h = size.height;
|
|
213
|
+
CGPoint p1 = CGPointMake(w * 0.32, h * 0.2);
|
|
214
|
+
CGPoint p2 = CGPointMake(w * 0.32, h * 0.8);
|
|
215
|
+
CGPoint p3 = CGPointMake(w * 0.78, h * 0.5);
|
|
216
|
+
CGContextBeginPath(context);
|
|
217
|
+
CGContextMoveToPoint(context, p1.x, p1.y);
|
|
218
|
+
CGContextAddLineToPoint(context, p2.x, p2.y);
|
|
219
|
+
CGContextAddLineToPoint(context, p3.x, p3.y);
|
|
220
|
+
CGContextClosePath(context);
|
|
221
|
+
CGContextFillPath(context);
|
|
222
|
+
}];
|
|
223
|
+
return img;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
- (UIImage *)_pauseIconWithSize:(CGSize)size color:(UIColor *)color {
|
|
227
|
+
if (!color) color = [UIColor blackColor];
|
|
228
|
+
UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:size];
|
|
229
|
+
UIImage *img = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull ctx) {
|
|
230
|
+
CGContextRef context = ctx.CGContext;
|
|
231
|
+
CGContextSetFillColorWithColor(context, color.CGColor);
|
|
232
|
+
CGFloat w = size.width;
|
|
233
|
+
CGFloat h = size.height;
|
|
234
|
+
CGFloat barW = w * 0.16;
|
|
235
|
+
CGFloat leftX = w * 0.3 - barW/2;
|
|
236
|
+
CGFloat rightX = w * 0.7 - barW/2;
|
|
237
|
+
CGRect leftRect = CGRectMake(leftX, h * 0.2, barW, h * 0.6);
|
|
238
|
+
CGRect rightRect = CGRectMake(rightX, h * 0.2, barW, h * 0.6);
|
|
239
|
+
CGContextFillRect(context, leftRect);
|
|
240
|
+
CGContextFillRect(context, rightRect);
|
|
241
|
+
}];
|
|
242
|
+
return img;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
- (void)setDuration:(double)seconds {
|
|
246
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
247
|
+
_slider.minimumValue = 0;
|
|
248
|
+
if (seconds > 0) {
|
|
249
|
+
_slider.maximumValue = (float)seconds;
|
|
250
|
+
} else {
|
|
251
|
+
_slider.maximumValue = 1.0f;
|
|
252
|
+
}
|
|
253
|
+
_durationSeconds = seconds;
|
|
254
|
+
_slider.enabled = (!isnan(seconds) && seconds > 0);
|
|
255
|
+
if (_slider.value > _slider.maximumValue) _slider.value = _slider.maximumValue;
|
|
256
|
+
[self updateTimeLabelWithCurrent:_slider.value duration:_durationSeconds];
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
- (void)updateTimeLabelWithCurrent:(double)seconds duration:(double)duration {
|
|
261
|
+
int total = (int)seconds;
|
|
262
|
+
int mins = total / 60;
|
|
263
|
+
int secs = total % 60;
|
|
264
|
+
int durationInt = (int)duration;
|
|
265
|
+
int dmins = durationInt / 60;
|
|
266
|
+
int dsecs = durationInt % 60;
|
|
267
|
+
_timeLabel.text = [NSString stringWithFormat:@"%d:%02d / %d:%02d", mins, secs, dmins, dsecs];
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
@end
|
|
@@ -18,6 +18,8 @@
|
|
|
18
18
|
- (void)onTimeUpdate:(double)seconds;
|
|
19
19
|
- (void)onStateChange:(NSCPlayerState)state;
|
|
20
20
|
- (void)onLoadedData;
|
|
21
|
+
- (void)onCanPlay;
|
|
22
|
+
- (void)onCanPlayThrough;
|
|
21
23
|
@end
|
|
22
24
|
|
|
23
25
|
@interface NSCVideoHelper : NSObject
|
|
@@ -43,4 +45,8 @@
|
|
|
43
45
|
- (void)play;
|
|
44
46
|
- (void)pause;
|
|
45
47
|
|
|
48
|
+
- (void)load;
|
|
49
|
+
|
|
50
|
+
- (NSString *)canPlayType:(NSString *)type;
|
|
51
|
+
|
|
46
52
|
@end
|
|
@@ -5,12 +5,16 @@
|
|
|
5
5
|
// Created by Osei Fortune on 20/05/2025.
|
|
6
6
|
//
|
|
7
7
|
#import "NSCVideoHelper.h"
|
|
8
|
+
#import <MobileCoreServices/MobileCoreServices.h>
|
|
8
9
|
#import "NSCVideoHelper+Internal.h"
|
|
9
10
|
|
|
10
|
-
@implementation NSCVideoHelper
|
|
11
|
+
@implementation NSCVideoHelper {
|
|
12
|
+
BOOL _canPlayFired;
|
|
13
|
+
BOOL _canPlayThroughFired;
|
|
14
|
+
}
|
|
11
15
|
|
|
12
16
|
- (instancetype)init {
|
|
13
|
-
|
|
17
|
+
_isLoop = NO;
|
|
14
18
|
if (self = [super init]) {
|
|
15
19
|
_controller = [[AVPlayerViewController alloc] init];
|
|
16
20
|
_player = [[AVPlayer alloc] init];
|
|
@@ -59,6 +63,8 @@
|
|
|
59
63
|
|
|
60
64
|
if (!src) return;
|
|
61
65
|
|
|
66
|
+
_canPlayFired = NO;
|
|
67
|
+
_canPlayThroughFired = NO;
|
|
62
68
|
NSURL *url = [src hasPrefix:@"/"] ? [NSURL fileURLWithPath:src] : [NSURL URLWithString:src];
|
|
63
69
|
if (!url) return;
|
|
64
70
|
|
|
@@ -88,7 +94,8 @@
|
|
|
88
94
|
}];
|
|
89
95
|
|
|
90
96
|
AVPlayerItem *item = [AVPlayerItem playerItemWithAsset:weakSelf.asset];
|
|
91
|
-
|
|
97
|
+
|
|
98
|
+
strongSelf->_currentItem = item;
|
|
92
99
|
|
|
93
100
|
NSDictionary *outputSettings = @{
|
|
94
101
|
(NSString *)kCVPixelBufferPixelFormatTypeKey: @(kCVPixelFormatType_32BGRA),
|
|
@@ -100,7 +107,32 @@
|
|
|
100
107
|
(NSString *)kCVPixelBufferMetalCompatibilityKey: @YES,
|
|
101
108
|
};
|
|
102
109
|
|
|
103
|
-
|
|
110
|
+
strongSelf->_assetOutput = [[AVPlayerItemVideoOutput alloc] initWithPixelBufferAttributes:outputSettings];
|
|
111
|
+
|
|
112
|
+
[item addObserver:strongSelf forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:nil];
|
|
113
|
+
[item addObserver:strongSelf forKeyPath:@"loadedTimeRanges" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial context:nil];
|
|
114
|
+
|
|
115
|
+
strongSelf->_playEndNotificationId = [[NSNotificationCenter defaultCenter]
|
|
116
|
+
addObserverForName:AVPlayerItemDidPlayToEndTimeNotification
|
|
117
|
+
object:item queue:nil usingBlock:^(NSNotification *note) {
|
|
118
|
+
__strong typeof(strongSelf) innerSelf = strongSelf;
|
|
119
|
+
if (!innerSelf) return;
|
|
120
|
+
if (innerSelf->_isLoop) {
|
|
121
|
+
[innerSelf->_player seekToTime:kCMTimeZero];
|
|
122
|
+
[innerSelf->_player play];
|
|
123
|
+
innerSelf->_state = NSCPlayerStatePlaying;
|
|
124
|
+
if ([innerSelf.listener respondsToSelector:@selector(onStateChange:)]) {
|
|
125
|
+
[innerSelf.listener onStateChange:innerSelf->_state];
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}];
|
|
129
|
+
|
|
130
|
+
[strongSelf.player replaceCurrentItemWithPlayerItem:item];
|
|
131
|
+
strongSelf.readyState = NSCPlayerReadyStateHaveMetadata;
|
|
132
|
+
[strongSelf performSelectorOnMainThread:@selector(_scheduleFirstFrameCheck) withObject:nil waitUntilDone:NO];
|
|
133
|
+
if (strongSelf.autoplay) {
|
|
134
|
+
[strongSelf play];
|
|
135
|
+
}
|
|
104
136
|
|
|
105
137
|
[item addObserver:strongSelf forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:nil];
|
|
106
138
|
[item addObserver:strongSelf forKeyPath:@"loadedTimeRanges" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial context:nil];
|
|
@@ -178,6 +210,33 @@
|
|
|
178
210
|
return CMTimeGetSeconds(_currentItem.asset.duration);
|
|
179
211
|
}
|
|
180
212
|
|
|
213
|
+
- (NSString *)canPlayType:(NSString *)type {
|
|
214
|
+
if (!type) return @"";
|
|
215
|
+
NSString *mime = [type lowercaseString];
|
|
216
|
+
NSRange sc = [mime rangeOfString:@";"];
|
|
217
|
+
if (sc.location != NSNotFound) {
|
|
218
|
+
mime = [mime substringToIndex:sc.location];
|
|
219
|
+
}
|
|
220
|
+
mime = [mime stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
|
|
221
|
+
|
|
222
|
+
@try {
|
|
223
|
+
CFStringRef uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, (__bridge CFStringRef)mime, NULL);
|
|
224
|
+
if (uti) {
|
|
225
|
+
if (UTTypeConformsTo(uti, kUTTypeVideo) || UTTypeConformsTo(uti, kUTTypeAudiovisualContent)) {
|
|
226
|
+
CFRelease(uti);
|
|
227
|
+
if ([mime containsString:@"webm"] || [mime containsString:@"vp8"] || [mime containsString:@"vp9"] || [mime containsString:@"ogg"]) return @"maybe";
|
|
228
|
+
return @"probably";
|
|
229
|
+
}
|
|
230
|
+
CFRelease(uti);
|
|
231
|
+
}
|
|
232
|
+
} @catch (NSException *ex) {}
|
|
233
|
+
|
|
234
|
+
if ([mime containsString:@"mp4"] || [mime containsString:@"mpeg"] || [mime containsString:@"h264"] || [mime containsString:@"video/mp4"]) return @"probably";
|
|
235
|
+
if ([mime containsString:@"webm"] || [mime containsString:@"vp8"] || [mime containsString:@"vp9"] || [mime containsString:@"video/webm"]) return @"maybe";
|
|
236
|
+
if ([mime containsString:@"ogg"] || [mime containsString:@"theora"] || [mime containsString:@"video/ogg"]) return @"maybe";
|
|
237
|
+
return @"";
|
|
238
|
+
}
|
|
239
|
+
|
|
181
240
|
- (double)currentTime {
|
|
182
241
|
return CMTimeGetSeconds(self.player.currentTime);
|
|
183
242
|
}
|
|
@@ -260,4 +319,52 @@
|
|
|
260
319
|
}
|
|
261
320
|
}
|
|
262
321
|
|
|
322
|
+
- (void)load {
|
|
323
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
324
|
+
@try {
|
|
325
|
+
[self pause];
|
|
326
|
+
|
|
327
|
+
if (self.playbackTimeObserver) {
|
|
328
|
+
[self.player removeTimeObserver:self.playbackTimeObserver];
|
|
329
|
+
self.playbackTimeObserver = nil;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (self.playbackFramesObserver) {
|
|
333
|
+
[self.player removeTimeObserver:self.playbackFramesObserver];
|
|
334
|
+
self.playbackFramesObserver = nil;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
if (_playEndNotificationId) {
|
|
338
|
+
[[NSNotificationCenter defaultCenter] removeObserver:_playEndNotificationId];
|
|
339
|
+
_playEndNotificationId = nil;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
if (self.currentItem) {
|
|
343
|
+
@try {
|
|
344
|
+
[self.currentItem removeObserver:self forKeyPath:@"status"];
|
|
345
|
+
} @catch (NSException *exception) {}
|
|
346
|
+
@try {
|
|
347
|
+
[self.currentItem removeObserver:self forKeyPath:@"loadedTimeRanges"];
|
|
348
|
+
} @catch (NSException *exception) {}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
if (self.assetOutput) {
|
|
352
|
+
[self.assetOutput setDelegate:nil queue:NULL];
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
[self.player replaceCurrentItemWithPlayerItem:nil];
|
|
356
|
+
|
|
357
|
+
self.loadedDataFired = NO;
|
|
358
|
+
|
|
359
|
+
if (self.currentSrc && self.currentSrc.length > 0) {
|
|
360
|
+
NSString *src = [self.currentSrc copy];
|
|
361
|
+
self.currentSrc = nil;
|
|
362
|
+
[self setSrc:src];
|
|
363
|
+
}
|
|
364
|
+
} @catch (NSException *ex) {
|
|
365
|
+
NSLog(@"NSCVideoHelper load() error: %@", ex);
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
|
|
263
370
|
@end
|
package/video/common.d.ts
CHANGED
|
@@ -11,8 +11,11 @@ export declare abstract class VideoBase extends MediaBase {
|
|
|
11
11
|
static playingEvent: string;
|
|
12
12
|
static playEvent: string;
|
|
13
13
|
static pauseEvent: string;
|
|
14
|
+
static canplayEvent: string;
|
|
15
|
+
static canplaythroughEvent: string;
|
|
14
16
|
static timeupdateEvent: string;
|
|
15
17
|
static durationchangeEvent: string;
|
|
18
|
+
static loadedmetadataEvent: string;
|
|
16
19
|
static loadeddataEvent: string;
|
|
17
20
|
static readonly HAVE_NOTHING = 0;
|
|
18
21
|
static readonly HAVE_METADATA = 1;
|
|
@@ -27,6 +30,7 @@ export declare abstract class VideoBase extends MediaBase {
|
|
|
27
30
|
private getSize;
|
|
28
31
|
abstract play(): Promise<void>;
|
|
29
32
|
abstract pause(): void;
|
|
33
|
+
abstract load(): void;
|
|
30
34
|
_capturedListeners: {};
|
|
31
35
|
_listeners: {};
|
|
32
36
|
_notifyListener(type: any): void;
|
package/video/common.js
CHANGED
|
@@ -187,8 +187,11 @@ let VideoBase = class VideoBase extends MediaBase {
|
|
|
187
187
|
VideoBase.playingEvent = 'playing';
|
|
188
188
|
VideoBase.playEvent = 'play';
|
|
189
189
|
VideoBase.pauseEvent = 'pause';
|
|
190
|
+
VideoBase.canplayEvent = 'canplay';
|
|
191
|
+
VideoBase.canplaythroughEvent = 'canplaythrough';
|
|
190
192
|
VideoBase.timeupdateEvent = 'timeupdate';
|
|
191
193
|
VideoBase.durationchangeEvent = 'durationchange';
|
|
194
|
+
VideoBase.loadedmetadataEvent = 'loadedmetadata';
|
|
192
195
|
VideoBase.loadeddataEvent = 'loadeddata';
|
|
193
196
|
VideoBase.HAVE_NOTHING = 0;
|
|
194
197
|
VideoBase.HAVE_METADATA = 1;
|
package/video/common.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../../packages/canvas-media/video/common.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxF,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAG/B,IAAe,SAAS,GAAxB,MAAe,SAAU,SAAQ,SAAS;IAA1C;;
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../../packages/canvas-media/video/common.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,EAAE,aAA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B,AAAnB,CAAoB;AACvC,yBAAe,GAAG,YAAY,AAAf,CAAgB;AACtB,sBAAY,GAAG,CAAC,AAAJ,CAAK;AACjB,uBAAa,GAAG,CAAC,AAAJ,CAAK;AAClB,2BAAiB,GAAG,CAAC,AAAJ,CAAK;AACtB,0BAAgB,GAAG,CAAC,AAAJ,CAAK;AACrB,0BAAgB,GAAG,CAAC,AAAJ,CAAK;AAtBvB,SAAS;IAD9B,OAAO,CAAC,OAAO,CAAC;GACK,SAAS,CAqM9B"}
|
package/video/index.android.d.ts
CHANGED
|
@@ -32,11 +32,13 @@ export declare class Video extends VideoBase {
|
|
|
32
32
|
pause(): void;
|
|
33
33
|
get muted(): boolean;
|
|
34
34
|
set muted(value: boolean);
|
|
35
|
-
get duration():
|
|
35
|
+
get duration(): number;
|
|
36
36
|
get currentTime(): number;
|
|
37
37
|
set currentTime(value: number);
|
|
38
38
|
get src(): string;
|
|
39
39
|
set src(value: string);
|
|
40
|
+
load(): void;
|
|
41
|
+
canPlayType(type: string): any;
|
|
40
42
|
get autoplay(): boolean;
|
|
41
43
|
set autoplay(value: boolean);
|
|
42
44
|
get controls(): boolean;
|
package/video/index.android.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { VideoBase } from './common';
|
|
2
|
-
import { Screen, Application, knownFolders, path } from '@nativescript/core';
|
|
2
|
+
import { Screen, Application, knownFolders, path, booleanConverter } from '@nativescript/core';
|
|
3
3
|
import { Source } from '..';
|
|
4
4
|
import { durationProperty, currentTimeProperty } from '../common';
|
|
5
5
|
export class Video extends VideoBase {
|
|
@@ -23,7 +23,8 @@ export class Video extends VideoBase {
|
|
|
23
23
|
onDurationChange(duration) {
|
|
24
24
|
const owner = ref.get();
|
|
25
25
|
if (owner) {
|
|
26
|
-
|
|
26
|
+
let secs = Number(duration) > 0 ? Number(duration) / 1000.0 : NaN;
|
|
27
|
+
durationProperty.nativeValueChange(owner, secs);
|
|
27
28
|
owner._notifyListener(Video.durationchangeEvent);
|
|
28
29
|
}
|
|
29
30
|
},
|
|
@@ -50,7 +51,8 @@ export class Video extends VideoBase {
|
|
|
50
51
|
onCurrentTimeChanged(time) {
|
|
51
52
|
const owner = ref.get();
|
|
52
53
|
if (owner) {
|
|
53
|
-
|
|
54
|
+
let secs = Number(time) / 1000.0;
|
|
55
|
+
currentTimeProperty.nativeValueChange(owner, secs);
|
|
54
56
|
owner._notifyListener(Video.timeupdateEvent);
|
|
55
57
|
}
|
|
56
58
|
},
|
|
@@ -64,9 +66,23 @@ export class Video extends VideoBase {
|
|
|
64
66
|
const owner = ref.get();
|
|
65
67
|
if (owner) {
|
|
66
68
|
owner._readyState = Video.HAVE_CURRENT_DATA;
|
|
69
|
+
owner._notifyListener(Video.durationchangeEvent);
|
|
70
|
+
owner._notifyListener(Video.loadedmetadataEvent);
|
|
67
71
|
owner._notifyListener(Video.loadeddataEvent);
|
|
68
72
|
}
|
|
69
73
|
},
|
|
74
|
+
onCanPlay() {
|
|
75
|
+
const owner = ref.get();
|
|
76
|
+
if (owner) {
|
|
77
|
+
owner._notifyListener(Video.canplayEvent);
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
onCanPlayThrough() {
|
|
81
|
+
const owner = ref.get();
|
|
82
|
+
if (owner) {
|
|
83
|
+
owner._notifyListener(Video.canplaythroughEvent);
|
|
84
|
+
}
|
|
85
|
+
},
|
|
70
86
|
onError(message) {
|
|
71
87
|
const owner = ref.get();
|
|
72
88
|
if (owner) {
|
|
@@ -194,10 +210,18 @@ export class Video extends VideoBase {
|
|
|
194
210
|
return this._instance.getMuted();
|
|
195
211
|
}
|
|
196
212
|
set muted(value) {
|
|
197
|
-
this._instance.setMuted(value);
|
|
213
|
+
this._instance.setMuted(booleanConverter(value));
|
|
198
214
|
}
|
|
199
215
|
get duration() {
|
|
200
|
-
|
|
216
|
+
try {
|
|
217
|
+
const d = this._instance.getDuration();
|
|
218
|
+
if (d == null || Number(d) <= 0)
|
|
219
|
+
return NaN;
|
|
220
|
+
return Number(d) / 1000.0;
|
|
221
|
+
}
|
|
222
|
+
catch (e) {
|
|
223
|
+
return NaN;
|
|
224
|
+
}
|
|
201
225
|
}
|
|
202
226
|
get currentTime() {
|
|
203
227
|
return this._instance.getCurrentTime();
|
|
@@ -214,25 +238,37 @@ export class Video extends VideoBase {
|
|
|
214
238
|
}
|
|
215
239
|
this._instance.setSrc(value);
|
|
216
240
|
}
|
|
241
|
+
load() {
|
|
242
|
+
if (!this._instance) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
this._instance.load();
|
|
246
|
+
}
|
|
247
|
+
canPlayType(type) {
|
|
248
|
+
if (!this._instance) {
|
|
249
|
+
return '';
|
|
250
|
+
}
|
|
251
|
+
return this._instance.canPlayType(type);
|
|
252
|
+
}
|
|
217
253
|
//@ts-ignore
|
|
218
254
|
get autoplay() {
|
|
219
255
|
return this._instance.getAutoplay();
|
|
220
256
|
}
|
|
221
257
|
set autoplay(value) {
|
|
222
|
-
this._instance.setAutoplay(value);
|
|
258
|
+
this._instance.setAutoplay(booleanConverter(value));
|
|
223
259
|
}
|
|
224
260
|
get controls() {
|
|
225
261
|
return this._instance.getControls();
|
|
226
262
|
}
|
|
227
263
|
set controls(enabled) {
|
|
228
|
-
this._instance.setControls(enabled);
|
|
264
|
+
this._instance.setControls(booleanConverter(enabled));
|
|
229
265
|
}
|
|
230
266
|
// @ts-ignore
|
|
231
267
|
get loop() {
|
|
232
268
|
return this._instance.getLoop();
|
|
233
269
|
}
|
|
234
270
|
set loop(value) {
|
|
235
|
-
this._instance.setLoop(value);
|
|
271
|
+
this._instance.setLoop(booleanConverter(value));
|
|
236
272
|
}
|
|
237
273
|
createNativeView() {
|
|
238
274
|
this._instance.setPlayer();
|