@nativescript/canvas-media 2.0.0-webgpu.4 → 2.0.0-webgpu.41
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/audio/common.d.ts +1 -2
- package/audio/common.js +1 -2
- package/audio/common.js.map +1 -1
- package/common.d.ts +1 -2
- package/common.js +1 -2
- package/common.js.map +1 -1
- package/package.json +1 -1
- package/platforms/android/canvas_media.aar +0 -0
- package/platforms/ios/src/NSCVideoHelper.swift +359 -0
- package/platforms/ios/src/NSCVideoHelperListener.swift +14 -0
- package/video/common.d.ts +1 -2
- package/video/common.js +1 -3
- package/video/common.js.map +1 -1
- package/video/index.ios.d.ts +7 -20
- package/video/index.ios.js +403 -216
- package/video/index.ios.js.map +1 -1
package/video/index.ios.js
CHANGED
|
@@ -1,114 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
-
};
|
|
6
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
7
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
|
-
};
|
|
12
|
-
var _Video_videoCtrl, _Video_player, _Video_sourceView, _Video_protocols, _Video_src, _Video_muted, _Video_controls;
|
|
13
|
-
import { controlsProperty, VideoBase, playsinlineProperty, currentTimeProperty } from './common';
|
|
1
|
+
import { controlsProperty, VideoBase, playsinlineProperty, loopProperty, autoplayProperty } from './common';
|
|
14
2
|
import { Source } from '../common';
|
|
15
3
|
import { knownFolders, path } from '@nativescript/core';
|
|
16
|
-
var
|
|
17
|
-
__extends(
|
|
18
|
-
function
|
|
4
|
+
var NSCVideoHelperListenerImpl = /** @class */ (function (_super) {
|
|
5
|
+
__extends(NSCVideoHelperListenerImpl, _super);
|
|
6
|
+
function NSCVideoHelperListenerImpl() {
|
|
19
7
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
20
8
|
}
|
|
21
|
-
|
|
22
|
-
|
|
9
|
+
NSCVideoHelperListenerImpl_1 = NSCVideoHelperListenerImpl;
|
|
10
|
+
NSCVideoHelperListenerImpl.initWithOwner = function (owner) {
|
|
11
|
+
var obj = NSCVideoHelperListenerImpl_1.alloc().init();
|
|
23
12
|
obj._owner = owner;
|
|
24
13
|
return obj;
|
|
25
14
|
};
|
|
26
|
-
|
|
27
|
-
var
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (owner._player.currentItem.status === AVPlayerItemStatus.Failed) {
|
|
32
|
-
var baseError = owner._player.currentItem.error.userInfo.objectForKey(NSUnderlyingErrorKey);
|
|
33
|
-
var error = new Error();
|
|
34
|
-
/*error: {
|
|
35
|
-
code: baseError.code,
|
|
36
|
-
domain: baseError.domain
|
|
37
|
-
},
|
|
38
|
-
stack: error.stack
|
|
39
|
-
|
|
40
|
-
*/
|
|
41
|
-
}
|
|
42
|
-
else if (owner._player.currentItem.status === AVPlayerItemStatus.ReadyToPlay) {
|
|
43
|
-
if (!owner._videoSize) {
|
|
44
|
-
owner._videoSize = (_b = (_a = owner._asset.tracksWithMediaType(AVMediaTypeVideo)) === null || _a === void 0 ? void 0 : _a.objectAtIndex(0).naturalSize) !== null && _b !== void 0 ? _b : undefined;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
15
|
+
NSCVideoHelperListenerImpl.prototype.onStateChange = function (state) {
|
|
16
|
+
var owner = this._owner.deref();
|
|
17
|
+
if (owner) {
|
|
18
|
+
if (state === 1) {
|
|
19
|
+
owner._notifyListener(Video.playingEvent);
|
|
47
20
|
}
|
|
48
21
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (first) {
|
|
55
|
-
var loaded = first.CMTimeRangeValue.duration.value / first.CMTimeRangeValue.duration.timescale;
|
|
56
|
-
var total = playerItem.duration.value / playerItem.duration.timescale;
|
|
57
|
-
// console.log('loaded', loaded / total);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
22
|
+
};
|
|
23
|
+
NSCVideoHelperListenerImpl.prototype.onTimeUpdate = function (time) {
|
|
24
|
+
var owner = this._owner.deref();
|
|
25
|
+
if (owner) {
|
|
26
|
+
owner._notifyListener(Video.timeupdateEvent);
|
|
60
27
|
}
|
|
61
28
|
};
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
var owner = this._owner.get();
|
|
29
|
+
NSCVideoHelperListenerImpl.prototype.onVideoFrameCallback = function () {
|
|
30
|
+
var owner = this._owner.deref();
|
|
65
31
|
if (owner) {
|
|
66
|
-
|
|
67
|
-
NSNotificationCenter.defaultCenter.removeObserver(owner._playEndNotificationId);
|
|
68
|
-
owner._playEndNotificationId = undefined;
|
|
69
|
-
NSNotificationCenter.defaultCenter.removeObserver(owner._resumeListenerId);
|
|
70
|
-
owner._resumeListenerId = undefined;
|
|
71
|
-
NSNotificationCenter.defaultCenter.removeObserver(owner._suspendListenerId);
|
|
72
|
-
owner._suspendListenerId = undefined;
|
|
73
|
-
owner._destroy();
|
|
74
|
-
}
|
|
32
|
+
owner._notifyVideoFrameCallbacks();
|
|
75
33
|
}
|
|
76
34
|
};
|
|
77
|
-
|
|
35
|
+
var NSCVideoHelperListenerImpl_1;
|
|
36
|
+
NSCVideoHelperListenerImpl = NSCVideoHelperListenerImpl_1 = __decorate([
|
|
37
|
+
ObjCClass(NSCVideoHelperListener)
|
|
38
|
+
], NSCVideoHelperListenerImpl);
|
|
39
|
+
return NSCVideoHelperListenerImpl;
|
|
78
40
|
}(NSObject));
|
|
79
41
|
export class Video extends VideoBase {
|
|
80
42
|
get _player() {
|
|
81
|
-
return
|
|
43
|
+
return this.helper.player;
|
|
82
44
|
}
|
|
83
45
|
constructor() {
|
|
84
46
|
super();
|
|
85
|
-
_Video_videoCtrl.set(this, void 0);
|
|
86
|
-
_Video_player.set(this, void 0);
|
|
87
|
-
_Video_sourceView.set(this, void 0);
|
|
88
|
-
_Video_protocols.set(this, void 0);
|
|
89
47
|
this._isCustom = false;
|
|
90
|
-
this._readyState = 0;
|
|
91
48
|
this._isInForground = true;
|
|
92
|
-
this.
|
|
93
|
-
_Video_src.set(this, void 0);
|
|
94
|
-
_Video_muted.set(this, void 0);
|
|
95
|
-
_Video_controls.set(this, void 0);
|
|
96
|
-
__classPrivateFieldSet(this, _Video_videoCtrl, AVPlayerViewController.new(), "f");
|
|
49
|
+
this.helper = NSCVideoHelper.alloc().init();
|
|
97
50
|
try {
|
|
98
51
|
AVAudioSession.sharedInstance().setCategoryError(AVAudioSessionCategoryPlayback);
|
|
99
52
|
}
|
|
100
53
|
catch (e) { }
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
this.setNativeView(__classPrivateFieldGet(this, _Video_videoCtrl, "f").view);
|
|
106
|
-
this._suspendListenerId = NSNotificationCenter.defaultCenter.addObserverForNameObjectQueueUsingBlock(UIApplicationDidEnterBackgroundNotification, null, null, (noti) => {
|
|
107
|
-
this._isInForground = false;
|
|
108
|
-
});
|
|
109
|
-
this._resumeListenerId = NSNotificationCenter.defaultCenter.addObserverForNameObjectQueueUsingBlock(UIApplicationDidBecomeActiveNotification, null, null, (noti) => {
|
|
110
|
-
this._isInForground = true;
|
|
111
|
-
});
|
|
54
|
+
this._sourceView = [];
|
|
55
|
+
this.listener = NSCVideoHelperListenerImpl.initWithOwner(new WeakRef(this));
|
|
56
|
+
this.helper.listener = this.listener;
|
|
57
|
+
this.setNativeView(this.helper.controller.view);
|
|
112
58
|
}
|
|
113
59
|
static createCustomView() {
|
|
114
60
|
const video = new Video();
|
|
@@ -119,23 +65,19 @@ export class Video extends VideoBase {
|
|
|
119
65
|
}
|
|
120
66
|
//@ts-ignore
|
|
121
67
|
get readyState() {
|
|
122
|
-
return this.
|
|
68
|
+
return this.helper.readyState;
|
|
123
69
|
}
|
|
124
70
|
getCurrentFrame(context) {
|
|
125
|
-
if (!this.
|
|
71
|
+
if (!this.helper.isInForground) {
|
|
126
72
|
return;
|
|
127
73
|
}
|
|
128
|
-
if (this.
|
|
74
|
+
if (this.helper.assetOutput) {
|
|
129
75
|
try {
|
|
130
|
-
|
|
131
|
-
this._render = Utils.setupRender();
|
|
132
|
-
this._render.createSurface();
|
|
133
|
-
}
|
|
134
|
-
Utils.drawFrame(__classPrivateFieldGet(this, _Video_player, "f"), this._assetOutput, this._videoSize, this._render, arguments[4], arguments[5], false);
|
|
76
|
+
NSCCanvasUtils.drawFrame(this.helper.player, this.helper.assetOutput, this.helper.videoSize, arguments[4], arguments[5], false);
|
|
135
77
|
}
|
|
136
78
|
catch (e) {
|
|
137
79
|
if (Video.IS_DEBUG) {
|
|
138
|
-
console.
|
|
80
|
+
console.error('getCurrentFrame error:', e);
|
|
139
81
|
}
|
|
140
82
|
}
|
|
141
83
|
}
|
|
@@ -143,172 +85,78 @@ export class Video extends VideoBase {
|
|
|
143
85
|
createNativeView() {
|
|
144
86
|
const ctrl = this.topViewController;
|
|
145
87
|
if (ctrl) {
|
|
146
|
-
ctrl.addChildViewController(
|
|
147
|
-
|
|
88
|
+
ctrl.addChildViewController(this.helper.controller);
|
|
89
|
+
this.helper.controller.didMoveToParentViewController(ctrl);
|
|
148
90
|
}
|
|
149
|
-
return
|
|
91
|
+
return this.helper.controller.view;
|
|
150
92
|
}
|
|
151
93
|
initNativeView() {
|
|
152
94
|
super.initNativeView();
|
|
153
|
-
__classPrivateFieldGet(this, _Video_videoCtrl, "f").showsPlaybackControls = this.controls;
|
|
154
|
-
__classPrivateFieldGet(this, _Video_videoCtrl, "f").entersFullScreenWhenPlaybackBegins = !this.playsinline;
|
|
155
|
-
__classPrivateFieldGet(this, _Video_player, "f").muted = this.muted;
|
|
156
95
|
}
|
|
157
|
-
[
|
|
158
|
-
|
|
96
|
+
[controlsProperty.setNative](enable) {
|
|
97
|
+
this.helper.controls = enable;
|
|
159
98
|
}
|
|
160
99
|
[playsinlineProperty.setNative](inline) {
|
|
161
|
-
|
|
100
|
+
this.helper.playsinline = inline;
|
|
101
|
+
}
|
|
102
|
+
[autoplayProperty.setNative](autoplay) {
|
|
103
|
+
this.helper.autoplay = autoplay;
|
|
162
104
|
}
|
|
163
105
|
_addChildFromBuilder(name, value) {
|
|
164
106
|
if (value instanceof Source) {
|
|
165
|
-
|
|
107
|
+
this._sourceView.push(value);
|
|
166
108
|
}
|
|
167
109
|
}
|
|
168
110
|
onLoaded() {
|
|
169
111
|
super.onLoaded();
|
|
170
|
-
const item =
|
|
112
|
+
const item = this._sourceView.filter((item) => {
|
|
171
113
|
if (item.type.indexOf('video/webm') === -1) {
|
|
172
114
|
return item;
|
|
173
115
|
}
|
|
174
116
|
})[0];
|
|
175
117
|
if (item) {
|
|
176
|
-
this.
|
|
118
|
+
this.helper.src = item.src;
|
|
177
119
|
}
|
|
178
120
|
}
|
|
179
121
|
get duration() {
|
|
180
|
-
|
|
181
|
-
if (currentItem) {
|
|
182
|
-
return CMTimeGetSeconds(currentItem.asset.duration);
|
|
183
|
-
}
|
|
184
|
-
return NaN;
|
|
122
|
+
return this.helper.duration;
|
|
185
123
|
}
|
|
186
124
|
get currentTime() {
|
|
187
|
-
|
|
188
|
-
return ct.value / ct.timescale;
|
|
125
|
+
return this.helper.currentTime;
|
|
189
126
|
}
|
|
190
127
|
set currentTime(value) {
|
|
191
|
-
|
|
192
|
-
__classPrivateFieldGet(this, _Video_player, "f").seekToTime(time);
|
|
128
|
+
this.helper.currentTime = value;
|
|
193
129
|
}
|
|
194
130
|
get muted() {
|
|
195
|
-
return
|
|
131
|
+
return this.helper.muted;
|
|
196
132
|
}
|
|
197
133
|
set muted(value) {
|
|
198
|
-
|
|
199
|
-
__classPrivateFieldGet(this, _Video_player, "f").muted = value;
|
|
134
|
+
this.helper.muted = value;
|
|
200
135
|
}
|
|
201
136
|
get src() {
|
|
202
|
-
return
|
|
137
|
+
return this.helper.src;
|
|
203
138
|
}
|
|
204
139
|
set src(value) {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
140
|
+
let src = value;
|
|
141
|
+
if (typeof src === 'string' && src.startsWith('~/')) {
|
|
142
|
+
src = path.join(knownFolders.currentApp().path, src.replace('~', ''));
|
|
208
143
|
}
|
|
144
|
+
this.helper.src = src;
|
|
209
145
|
}
|
|
210
146
|
get controls() {
|
|
211
|
-
return
|
|
147
|
+
return this.helper.controls;
|
|
212
148
|
}
|
|
213
149
|
set controls(enabled) {
|
|
214
|
-
|
|
215
|
-
__classPrivateFieldGet(this, _Video_videoCtrl, "f").showsPlaybackControls = enabled;
|
|
216
|
-
}
|
|
217
|
-
_addTimeObserver() {
|
|
218
|
-
const _interval = CMTimeMake(1, 1);
|
|
219
|
-
this._playbackTimeObserver = __classPrivateFieldGet(this, _Video_player, "f").addPeriodicTimeObserverForIntervalQueueUsingBlock(_interval, null, (currentTime) => {
|
|
220
|
-
if (this._isPlaying) {
|
|
221
|
-
const _seconds = CMTimeGetSeconds(currentTime);
|
|
222
|
-
currentTimeProperty.nativeValueChange(this, _seconds);
|
|
223
|
-
this._notifyListener(Video.timeupdateEvent);
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
_loadSrc(value) {
|
|
228
|
-
try {
|
|
229
|
-
const src = value;
|
|
230
|
-
let url;
|
|
231
|
-
if (typeof value === 'string' && value.startsWith('~/')) {
|
|
232
|
-
value = path.join(knownFolders.currentApp().path, value.replace('~', ''));
|
|
233
|
-
}
|
|
234
|
-
if (typeof value === 'string' && value.startsWith('/')) {
|
|
235
|
-
url = NSURL.fileURLWithPath(value);
|
|
236
|
-
}
|
|
237
|
-
if (this._playEndNotificationId) {
|
|
238
|
-
NSNotificationCenter.defaultCenter.removeObserver(this._playEndNotificationId);
|
|
239
|
-
this._playEndNotificationId = undefined;
|
|
240
|
-
}
|
|
241
|
-
if (!url) {
|
|
242
|
-
url = NSURL.URLWithString(value);
|
|
243
|
-
}
|
|
244
|
-
this._asset = AVURLAsset.assetWithURL(url);
|
|
245
|
-
const keys = ['tracks', 'duration'];
|
|
246
|
-
this._asset.loadValuesAsynchronouslyForKeysCompletionHandler(keys, () => {
|
|
247
|
-
this._videoSize = this._asset.tracksWithMediaType(AVMediaTypeVideo)?.objectAtIndex(0).naturalSize ?? undefined;
|
|
248
|
-
const fps = this._asset.tracks.firstObject?.nominalFrameRate ?? 30;
|
|
249
|
-
const _interval = CMTimeMake(1, fps);
|
|
250
|
-
this._playbackFramesObserver = __classPrivateFieldGet(this, _Video_player, "f").addPeriodicTimeObserverForIntervalQueueUsingBlock(_interval, null, (currentTime) => {
|
|
251
|
-
if (this._isPlaying) {
|
|
252
|
-
this._notifyVideoFrameCallbacks();
|
|
253
|
-
}
|
|
254
|
-
});
|
|
255
|
-
this._render?.destroy();
|
|
256
|
-
this._render = undefined;
|
|
257
|
-
const item = AVPlayerItem.alloc().initWithAsset(this._asset);
|
|
258
|
-
const settings = {};
|
|
259
|
-
settings[kCVPixelBufferPixelFormatTypeKey] = NSNumber.numberWithUnsignedInt(kCVPixelFormatType_32BGRA);
|
|
260
|
-
this._assetOutput = AVPlayerItemVideoOutput.alloc().initWithOutputSettings(settings);
|
|
261
|
-
item.addOutput(this._assetOutput);
|
|
262
|
-
item.addObserverForKeyPathOptionsContext(__classPrivateFieldGet(this, _Video_protocols, "f"), 'status', 1 /* NSKeyValueObservingOptions.New */, null);
|
|
263
|
-
item.addObserverForKeyPathOptionsContext(__classPrivateFieldGet(this, _Video_protocols, "f"), 'loadedTimeRanges', 4 /* NSKeyValueObservingOptions.Initial */ | 1 /* NSKeyValueObservingOptions.New */, null);
|
|
264
|
-
this._playEndNotificationId = NSNotificationCenter.defaultCenter.addObserverForNameObjectQueueUsingBlock(AVPlayerItemDidPlayToEndTimeNotification, item, null, (notfi) => {
|
|
265
|
-
if (this.loop) {
|
|
266
|
-
__classPrivateFieldGet(this, _Video_player, "f").seekToTime(kCMTimeZero);
|
|
267
|
-
__classPrivateFieldGet(this, _Video_player, "f").play();
|
|
268
|
-
this._isPlaying = true;
|
|
269
|
-
this._notifyListener(Video.playingEvent);
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
__classPrivateFieldGet(this, _Video_player, "f").replaceCurrentItemWithPlayerItem(item);
|
|
273
|
-
this._readyState = Video.HAVE_METADATA;
|
|
274
|
-
this._currentUrl = src;
|
|
275
|
-
if (this.autoplay) {
|
|
276
|
-
this.play();
|
|
277
|
-
}
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
catch (e) {
|
|
281
|
-
console.log('_loadSrc', e);
|
|
282
|
-
}
|
|
150
|
+
this.helper.controls = enabled;
|
|
283
151
|
}
|
|
284
152
|
play() {
|
|
285
|
-
|
|
286
|
-
return;
|
|
287
|
-
}
|
|
288
|
-
this._addTimeObserver();
|
|
289
|
-
__classPrivateFieldGet(this, _Video_player, "f").play();
|
|
290
|
-
this._isPlaying = true;
|
|
291
|
-
this._notifyListener(Video.playingEvent);
|
|
153
|
+
this.helper.play();
|
|
292
154
|
}
|
|
293
155
|
pause() {
|
|
294
|
-
|
|
295
|
-
return;
|
|
296
|
-
}
|
|
297
|
-
if (this._playbackTimeObserver) {
|
|
298
|
-
__classPrivateFieldGet(this, _Video_player, "f").removeTimeObserver(this._playbackTimeObserver);
|
|
299
|
-
this._playbackTimeObserver = undefined;
|
|
300
|
-
}
|
|
301
|
-
/*
|
|
302
|
-
if (this._playbackTimeObserver) {
|
|
303
|
-
this.#player.removeTimeObserver(this._playbackTimeObserver);
|
|
304
|
-
this._playbackTimeObserver = undefined;
|
|
305
|
-
}
|
|
306
|
-
*/
|
|
307
|
-
__classPrivateFieldGet(this, _Video_player, "f").pause();
|
|
308
|
-
this._isPlaying = false;
|
|
156
|
+
this.helper.pause();
|
|
309
157
|
}
|
|
310
|
-
|
|
311
|
-
|
|
158
|
+
[loopProperty.setNative](value) {
|
|
159
|
+
this.helper.isLoop = value;
|
|
312
160
|
}
|
|
313
161
|
static get rootViewController() {
|
|
314
162
|
const keyWindow = UIApplication.sharedApplication.keyWindow;
|
|
@@ -353,4 +201,343 @@ export class Video extends VideoBase {
|
|
|
353
201
|
}
|
|
354
202
|
}
|
|
355
203
|
Video.IS_DEBUG = false;
|
|
204
|
+
// @NativeClass()
|
|
205
|
+
// class NativeObject extends NSObject {
|
|
206
|
+
// _owner: WeakRef<Video>;
|
|
207
|
+
// public static initWithOwner(owner: WeakRef<Video>): NativeObject {
|
|
208
|
+
// const obj = NativeObject.alloc().init() as NativeObject;
|
|
209
|
+
// obj._owner = owner;
|
|
210
|
+
// return obj;
|
|
211
|
+
// }
|
|
212
|
+
// observeValueForKeyPathOfObjectChangeContext(path: string, obj: Object, change: NSDictionary<any, any>, context: any) {
|
|
213
|
+
// if (path === 'status') {
|
|
214
|
+
// const owner = this._owner.get();
|
|
215
|
+
// if (owner) {
|
|
216
|
+
// if (owner._player.currentItem.status === AVPlayerItemStatus.Failed) {
|
|
217
|
+
// const baseError = owner._player.currentItem.error.userInfo.objectForKey(NSUnderlyingErrorKey);
|
|
218
|
+
// const error = new Error();
|
|
219
|
+
// /*error: {
|
|
220
|
+
// code: baseError.code,
|
|
221
|
+
// domain: baseError.domain
|
|
222
|
+
// },
|
|
223
|
+
// stack: error.stack
|
|
224
|
+
// */
|
|
225
|
+
// } else if (owner._player.currentItem.status === AVPlayerItemStatus.ReadyToPlay) {
|
|
226
|
+
// if (!owner._videoSize) {
|
|
227
|
+
// owner._videoSize = owner._asset.tracksWithMediaType(AVMediaTypeVideo)?.objectAtIndex(0).naturalSize ?? undefined;
|
|
228
|
+
// }
|
|
229
|
+
// }
|
|
230
|
+
// }
|
|
231
|
+
// } else if (path === 'loadedTimeRanges') {
|
|
232
|
+
// const playerItem = obj as AVPlayerItem;
|
|
233
|
+
// if (playerItem) {
|
|
234
|
+
// const ranges = playerItem.loadedTimeRanges;
|
|
235
|
+
// const first = ranges?.firstObject as NSValue;
|
|
236
|
+
// if (first) {
|
|
237
|
+
// let loaded = first.CMTimeRangeValue.duration.value / first.CMTimeRangeValue.duration.timescale;
|
|
238
|
+
// let total = playerItem.duration.value / playerItem.duration.timescale;
|
|
239
|
+
// // console.log('loaded', loaded / total);
|
|
240
|
+
// }
|
|
241
|
+
// }
|
|
242
|
+
// }
|
|
243
|
+
// }
|
|
244
|
+
// dealloc() {
|
|
245
|
+
// // using this to clean up listeners
|
|
246
|
+
// const owner = this._owner.get();
|
|
247
|
+
// if (owner) {
|
|
248
|
+
// if (owner._playEndNotificationId) {
|
|
249
|
+
// NSNotificationCenter.defaultCenter.removeObserver(owner._playEndNotificationId);
|
|
250
|
+
// owner._playEndNotificationId = undefined;
|
|
251
|
+
// NSNotificationCenter.defaultCenter.removeObserver(owner._resumeListenerId);
|
|
252
|
+
// owner._resumeListenerId = undefined;
|
|
253
|
+
// NSNotificationCenter.defaultCenter.removeObserver(owner._suspendListenerId);
|
|
254
|
+
// owner._suspendListenerId = undefined;
|
|
255
|
+
// owner._destroy();
|
|
256
|
+
// }
|
|
257
|
+
// }
|
|
258
|
+
// }
|
|
259
|
+
// }
|
|
260
|
+
// export class Video extends VideoBase {
|
|
261
|
+
// #videoCtrl: AVPlayerViewController;
|
|
262
|
+
// #player: AVPlayer;
|
|
263
|
+
// #sourceView: Source[];
|
|
264
|
+
// #protocols: NativeObject;
|
|
265
|
+
// _isCustom: boolean = false;
|
|
266
|
+
// _readyState: number = 0;
|
|
267
|
+
// _resumeListenerId: any;
|
|
268
|
+
// _suspendListenerId: any;
|
|
269
|
+
// _isInForground = true;
|
|
270
|
+
// _assetOutput: AVPlayerItemVideoOutput;
|
|
271
|
+
// _isPlaying = false;
|
|
272
|
+
// #src: string;
|
|
273
|
+
// #muted: boolean;
|
|
274
|
+
// #controls: boolean;
|
|
275
|
+
// _playEndNotificationId: any;
|
|
276
|
+
// _playbackTimeObserver: any;
|
|
277
|
+
// _playbackFramesObserver: any;
|
|
278
|
+
// _currentUrl: string;
|
|
279
|
+
// _fps: number;
|
|
280
|
+
// _ctx: any;
|
|
281
|
+
// _asset: AVURLAsset;
|
|
282
|
+
// _videoSize: any;
|
|
283
|
+
// _render: any;
|
|
284
|
+
// static IS_DEBUG = false;
|
|
285
|
+
// get _player() {
|
|
286
|
+
// return this.#player;
|
|
287
|
+
// }
|
|
288
|
+
// constructor() {
|
|
289
|
+
// super();
|
|
290
|
+
// this.#videoCtrl = AVPlayerViewController.new();
|
|
291
|
+
// try {
|
|
292
|
+
// AVAudioSession.sharedInstance().setCategoryError(AVAudioSessionCategoryPlayback);
|
|
293
|
+
// } catch (e) {}
|
|
294
|
+
// this.#player = AVPlayer.new();
|
|
295
|
+
// this.#videoCtrl.player = this.#player;
|
|
296
|
+
// this.#sourceView = [];
|
|
297
|
+
// this.#protocols = NativeObject.initWithOwner(new WeakRef(this));
|
|
298
|
+
// this.setNativeView(this.#videoCtrl.view);
|
|
299
|
+
// this._suspendListenerId = NSNotificationCenter.defaultCenter.addObserverForNameObjectQueueUsingBlock(UIApplicationDidEnterBackgroundNotification, null, null, (noti) => {
|
|
300
|
+
// this._isInForground = false;
|
|
301
|
+
// });
|
|
302
|
+
// this._resumeListenerId = NSNotificationCenter.defaultCenter.addObserverForNameObjectQueueUsingBlock(UIApplicationDidBecomeActiveNotification, null, null, (noti) => {
|
|
303
|
+
// this._isInForground = true;
|
|
304
|
+
// });
|
|
305
|
+
// }
|
|
306
|
+
// static createCustomView() {
|
|
307
|
+
// const video = new Video();
|
|
308
|
+
// video._isCustom = true;
|
|
309
|
+
// video.width = 300;
|
|
310
|
+
// video.height = 150;
|
|
311
|
+
// return video;
|
|
312
|
+
// }
|
|
313
|
+
// //@ts-ignore
|
|
314
|
+
// get readyState() {
|
|
315
|
+
// return this._readyState;
|
|
316
|
+
// }
|
|
317
|
+
// getCurrentFrame(context) {
|
|
318
|
+
// if (!this._isInForground) {
|
|
319
|
+
// return;
|
|
320
|
+
// }
|
|
321
|
+
// if (this._assetOutput) {
|
|
322
|
+
// try {
|
|
323
|
+
// if (!this._render) {
|
|
324
|
+
// this._render = NSCCanvasUtils.setupRender();
|
|
325
|
+
// this._render.createSurface();
|
|
326
|
+
// }
|
|
327
|
+
// NSCCanvasUtils.drawFrame(this.#player, this._assetOutput, this._videoSize, this._render, arguments[4], arguments[5], false);
|
|
328
|
+
// } catch (e) {
|
|
329
|
+
// if (Video.IS_DEBUG) {
|
|
330
|
+
// console.error('getCurrentFrame error:', e);
|
|
331
|
+
// }
|
|
332
|
+
// }
|
|
333
|
+
// }
|
|
334
|
+
// }
|
|
335
|
+
// createNativeView(): Object {
|
|
336
|
+
// const ctrl = this.topViewController;
|
|
337
|
+
// if (ctrl) {
|
|
338
|
+
// ctrl.addChildViewController(this.#videoCtrl);
|
|
339
|
+
// this.#videoCtrl.didMoveToParentViewController(ctrl);
|
|
340
|
+
// }
|
|
341
|
+
// return this.#videoCtrl.view;
|
|
342
|
+
// }
|
|
343
|
+
// initNativeView() {
|
|
344
|
+
// super.initNativeView();
|
|
345
|
+
// this.#videoCtrl.showsPlaybackControls = this.controls;
|
|
346
|
+
// this.#videoCtrl.entersFullScreenWhenPlaybackBegins = !this.playsinline;
|
|
347
|
+
// this.#player.muted = this.muted;
|
|
348
|
+
// }
|
|
349
|
+
// [controlsProperty.setNative](enable: boolean) {
|
|
350
|
+
// this.#videoCtrl.showsPlaybackControls = enable;
|
|
351
|
+
// }
|
|
352
|
+
// [playsinlineProperty.setNative](inline: boolean) {
|
|
353
|
+
// this.#videoCtrl.entersFullScreenWhenPlaybackBegins = !inline;
|
|
354
|
+
// }
|
|
355
|
+
// _addChildFromBuilder(name: string, value: any) {
|
|
356
|
+
// if (value instanceof Source) {
|
|
357
|
+
// this.#sourceView.push(value);
|
|
358
|
+
// }
|
|
359
|
+
// }
|
|
360
|
+
// onLoaded() {
|
|
361
|
+
// super.onLoaded();
|
|
362
|
+
// const item = this.#sourceView.filter((item) => {
|
|
363
|
+
// if (item.type.indexOf('video/webm') === -1) {
|
|
364
|
+
// return item;
|
|
365
|
+
// }
|
|
366
|
+
// })[0];
|
|
367
|
+
// if (item) {
|
|
368
|
+
// this._loadSrc(item.src);
|
|
369
|
+
// }
|
|
370
|
+
// }
|
|
371
|
+
// get duration() {
|
|
372
|
+
// const currentItem = this.#player.currentItem;
|
|
373
|
+
// if (currentItem) {
|
|
374
|
+
// return CMTimeGetSeconds(currentItem.asset.duration);
|
|
375
|
+
// }
|
|
376
|
+
// return NaN;
|
|
377
|
+
// }
|
|
378
|
+
// get currentTime() {
|
|
379
|
+
// const ct = this.#player.currentTime();
|
|
380
|
+
// return ct.value / ct.timescale;
|
|
381
|
+
// }
|
|
382
|
+
// set currentTime(value: number) {
|
|
383
|
+
// const time = CMTimeMakeWithSeconds(value, this.#player.currentTime().timescale);
|
|
384
|
+
// this.#player.seekToTime(time);
|
|
385
|
+
// }
|
|
386
|
+
// get muted() {
|
|
387
|
+
// return this.#muted;
|
|
388
|
+
// }
|
|
389
|
+
// set muted(value: boolean) {
|
|
390
|
+
// this.#muted = value;
|
|
391
|
+
// this.#player.muted = value;
|
|
392
|
+
// }
|
|
393
|
+
// get src() {
|
|
394
|
+
// return this.#src;
|
|
395
|
+
// }
|
|
396
|
+
// set src(value: string) {
|
|
397
|
+
// if (value !== this._currentUrl) {
|
|
398
|
+
// this.#src = value;
|
|
399
|
+
// this._loadSrc(value);
|
|
400
|
+
// }
|
|
401
|
+
// }
|
|
402
|
+
// get controls() {
|
|
403
|
+
// return this.#controls;
|
|
404
|
+
// }
|
|
405
|
+
// set controls(enabled: boolean) {
|
|
406
|
+
// this.#controls = enabled;
|
|
407
|
+
// this.#videoCtrl.showsPlaybackControls = enabled;
|
|
408
|
+
// }
|
|
409
|
+
// private _addTimeObserver() {
|
|
410
|
+
// const _interval = CMTimeMake(1, 1);
|
|
411
|
+
// this._playbackTimeObserver = this.#player.addPeriodicTimeObserverForIntervalQueueUsingBlock(_interval, null, (currentTime) => {
|
|
412
|
+
// if (this._isPlaying) {
|
|
413
|
+
// const _seconds = CMTimeGetSeconds(currentTime);
|
|
414
|
+
// currentTimeProperty.nativeValueChange(this, _seconds);
|
|
415
|
+
// this._notifyListener(Video.timeupdateEvent);
|
|
416
|
+
// }
|
|
417
|
+
// });
|
|
418
|
+
// }
|
|
419
|
+
// private _loadSrc(value: string) {
|
|
420
|
+
// try {
|
|
421
|
+
// const src = value;
|
|
422
|
+
// let url;
|
|
423
|
+
// if (typeof value === 'string' && value.startsWith('~/')) {
|
|
424
|
+
// value = path.join(knownFolders.currentApp().path, value.replace('~', ''));
|
|
425
|
+
// }
|
|
426
|
+
// if (typeof value === 'string' && value.startsWith('/')) {
|
|
427
|
+
// url = NSURL.fileURLWithPath(value);
|
|
428
|
+
// }
|
|
429
|
+
// if (this._playEndNotificationId) {
|
|
430
|
+
// NSNotificationCenter.defaultCenter.removeObserver(this._playEndNotificationId);
|
|
431
|
+
// this._playEndNotificationId = undefined;
|
|
432
|
+
// }
|
|
433
|
+
// if (!url) {
|
|
434
|
+
// url = NSURL.URLWithString(value);
|
|
435
|
+
// }
|
|
436
|
+
// this._asset = AVURLAsset.assetWithURL(url);
|
|
437
|
+
// const keys = ['tracks', 'duration'];
|
|
438
|
+
// this._asset.loadValuesAsynchronouslyForKeysCompletionHandler(keys, () => {
|
|
439
|
+
// this._videoSize = this._asset.tracksWithMediaType(AVMediaTypeVideo)?.objectAtIndex(0).naturalSize ?? undefined;
|
|
440
|
+
// const fps = this._asset.tracks.firstObject?.nominalFrameRate ?? 30;
|
|
441
|
+
// const _interval = CMTimeMake(1, fps);
|
|
442
|
+
// this._playbackFramesObserver = this.#player.addPeriodicTimeObserverForIntervalQueueUsingBlock(_interval, null, (currentTime) => {
|
|
443
|
+
// if (this._isPlaying) {
|
|
444
|
+
// this._notifyVideoFrameCallbacks();
|
|
445
|
+
// }
|
|
446
|
+
// });
|
|
447
|
+
// this._render?.destroy();
|
|
448
|
+
// this._render = undefined;
|
|
449
|
+
// const item = AVPlayerItem.alloc().initWithAsset(this._asset);
|
|
450
|
+
// const settings: any = {};
|
|
451
|
+
// settings[kCVPixelBufferPixelFormatTypeKey] = NSNumber.numberWithUnsignedInt(kCVPixelFormatType_32BGRA);
|
|
452
|
+
// this._assetOutput = AVPlayerItemVideoOutput.alloc().initWithOutputSettings(settings);
|
|
453
|
+
// item.addOutput(this._assetOutput);
|
|
454
|
+
// item.addObserverForKeyPathOptionsContext(this.#protocols, 'status', NSKeyValueObservingOptions.New, null);
|
|
455
|
+
// item.addObserverForKeyPathOptionsContext(this.#protocols, 'loadedTimeRanges', NSKeyValueObservingOptions.Initial | NSKeyValueObservingOptions.New, null);
|
|
456
|
+
// this._playEndNotificationId = NSNotificationCenter.defaultCenter.addObserverForNameObjectQueueUsingBlock(AVPlayerItemDidPlayToEndTimeNotification, item, null, (notfi) => {
|
|
457
|
+
// if (this.loop) {
|
|
458
|
+
// this.#player.seekToTime(kCMTimeZero);
|
|
459
|
+
// this.#player.play();
|
|
460
|
+
// this._isPlaying = true;
|
|
461
|
+
// this._notifyListener(Video.playingEvent);
|
|
462
|
+
// }
|
|
463
|
+
// });
|
|
464
|
+
// this.#player.replaceCurrentItemWithPlayerItem(item);
|
|
465
|
+
// this._readyState = Video.HAVE_METADATA;
|
|
466
|
+
// this._currentUrl = src;
|
|
467
|
+
// if (this.autoplay) {
|
|
468
|
+
// this.play();
|
|
469
|
+
// }
|
|
470
|
+
// });
|
|
471
|
+
// } catch (e) {
|
|
472
|
+
// console.log('_loadSrc', e);
|
|
473
|
+
// }
|
|
474
|
+
// }
|
|
475
|
+
// play() {
|
|
476
|
+
// if (this._isPlaying) {
|
|
477
|
+
// return;
|
|
478
|
+
// }
|
|
479
|
+
// this._addTimeObserver();
|
|
480
|
+
// this.#player.play();
|
|
481
|
+
// this._isPlaying = true;
|
|
482
|
+
// this._notifyListener(Video.playingEvent);
|
|
483
|
+
// }
|
|
484
|
+
// pause() {
|
|
485
|
+
// if (!this._isPlaying) {
|
|
486
|
+
// return;
|
|
487
|
+
// }
|
|
488
|
+
// if (this._playbackTimeObserver) {
|
|
489
|
+
// this.#player.removeTimeObserver(this._playbackTimeObserver);
|
|
490
|
+
// this._playbackTimeObserver = undefined;
|
|
491
|
+
// }
|
|
492
|
+
// /*
|
|
493
|
+
// if (this._playbackTimeObserver) {
|
|
494
|
+
// this.#player.removeTimeObserver(this._playbackTimeObserver);
|
|
495
|
+
// this._playbackTimeObserver = undefined;
|
|
496
|
+
// }
|
|
497
|
+
// */
|
|
498
|
+
// this.#player.pause();
|
|
499
|
+
// this._isPlaying = false;
|
|
500
|
+
// }
|
|
501
|
+
// _destroy() {
|
|
502
|
+
// this.#player.pause();
|
|
503
|
+
// }
|
|
504
|
+
// private static get rootViewController(): UIViewController | undefined {
|
|
505
|
+
// const keyWindow = UIApplication.sharedApplication.keyWindow;
|
|
506
|
+
// return keyWindow != null ? keyWindow.rootViewController : undefined;
|
|
507
|
+
// }
|
|
508
|
+
// private get topViewController(): UIViewController | undefined {
|
|
509
|
+
// const root = Video.rootViewController;
|
|
510
|
+
// if (root == null) {
|
|
511
|
+
// return undefined;
|
|
512
|
+
// }
|
|
513
|
+
// return this.findTopViewController(root);
|
|
514
|
+
// }
|
|
515
|
+
// private findTopViewController(root: UIViewController): UIViewController | undefined {
|
|
516
|
+
// const presented = root.presentedViewController;
|
|
517
|
+
// if (presented != null) {
|
|
518
|
+
// return this.findTopViewController(presented);
|
|
519
|
+
// }
|
|
520
|
+
// if (root instanceof UISplitViewController) {
|
|
521
|
+
// const last = root.viewControllers.lastObject;
|
|
522
|
+
// if (last == null) {
|
|
523
|
+
// return root;
|
|
524
|
+
// }
|
|
525
|
+
// return this.findTopViewController(last);
|
|
526
|
+
// } else if (root instanceof UINavigationController) {
|
|
527
|
+
// const top = root.topViewController;
|
|
528
|
+
// if (top == null) {
|
|
529
|
+
// return root;
|
|
530
|
+
// }
|
|
531
|
+
// return this.findTopViewController(top);
|
|
532
|
+
// } else if (root instanceof UITabBarController) {
|
|
533
|
+
// const selected = root.selectedViewController;
|
|
534
|
+
// if (selected == null) {
|
|
535
|
+
// return root;
|
|
536
|
+
// }
|
|
537
|
+
// return this.findTopViewController(selected);
|
|
538
|
+
// } else {
|
|
539
|
+
// return root;
|
|
540
|
+
// }
|
|
541
|
+
// }
|
|
542
|
+
// }
|
|
356
543
|
//# sourceMappingURL=index.ios.js.map
|