This repository has been archived by the owner on Jan 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
index.d.ts
4145 lines (3924 loc) · 136 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Type definitions for non-npm package wegame 2.8
// Project: https://developers.weixin.qq.com/minigame/dev/index.html
// Definitions by: J.C <https://github.com/jcyuan>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.0
/**
* IOS及安卓不支持:
* globalCompositeOperation不支持以下值:source-in source-out destination-atop lighter copy
* isPointInPath 不支持
*/
declare class WxRenderingContext extends CanvasRenderingContext2D {
}
/**
* IOS及安卓不支持:
* pixelStorei 当第一个参数是 gl.UNPACK_COLORSPACE_CONVERSION_WEBGL 时不支持
* compressedTexImage2D不支持
* compressedTexSubImage2D不支持
* 安卓不支持:
* getExtension
* getSupportedExtensions
*/
declare class WxWebGLRenderingContext extends WebGLRenderingContext {
/**
* 将一个Canvas对应的Texture绑定到WebGL上下文。(目前该方法仅支持 iOS 6.6.6 以上版本,Android/开发者工具暂不支持。)
* 示例:gl.wxBindCanvasTexture(gl.TEXTURE_2D, canvas)
* @param texture WebGL的纹理类型枚举值
* @param canvas 需要绑定为Texture的Canvas
*/
wxBindCanvasTexture(texture: number, canvas: Canvas): void;
}
declare class WxPerformance {
/**
* 时间戳
*/
now(): number;
}
declare class Canvas {
/**
* 画布的宽度
*/
width: number;
/**
* 画布的高度
*/
height: number;
/**
* 将当前 Canvas 保存为一个临时文件,并生成相应的临时文件路径。
*/
toTempFilePath(p: wx.types.ToTempFileParams): void;
/**
* toTempFilePath 的同步版本
*/
toTempFilePathSync(p: wx.types.ToTempFileSyncParams): string;
/**
* 获取画布对象的绘图上下文
* @param contextType 上下文类型
* @param contextAttributes webgl 上下文属性,仅当 contextType 为 webgl 时有效
*/
getContext(contextType: "2d" | "webgl", contextAttributes?: wx.types.RenderingContextConfig): WxRenderingContext | WxWebGLRenderingContext;
/**
* 把画布上的绘制内容以一个 data URI 的格式返回
*/
toDataURL(): string;
}
declare class Stats {
/**
* 文件的类型和存取的权限,对应 POSIX stat.st_mode
*/
mode: string;
/**
* 文件大小,单位:B,对应 POSIX stat.st_size
*/
size: number;
/**
* 文件最近一次被存取或被执行的时间,UNIX 时间戳,对应 POSIX stat.st_atime
*/
lastAccessedTime: number;
/**
* 文件最后一次被修改的时间,UNIX 时间戳,对应 POSIX stat.st_mtime
*/
lastModifiedTime: number;
/**
* 判断当前文件是否一个目录
*/
isDirectory(): boolean;
/**
* 判断当前文件是否一个普通文件
*/
isFile(): boolean;
}
/**
* 日志管理类,最多保存5M的日志内容,超过5M后,旧的日志内容会被删除。
* 对于小程序,用户可以通过使用 button 组件的 open-type="feedback" 来上传打印的日志。
* 对于小游戏,用户可以通过使用 wx.createFeedbackButton 来创建上传打印的日志的按钮。
* 开发者可以通过小程序管理后台左侧菜单“反馈管理”页面查看相关打印日志。
* 基础库默认会把 App、Page 的生命周期函数和 wx 命名空间下的函数调用写入日志。
*/
declare class LogManager {
/**
* 写debug日志
* @param args 要记录的日志内容
*/
debug(... args: unknown[]): void;
/**
* 写info日志
* @param args 要记录的日志内容
*/
info(... args: unknown[]): void;
/**
* 写log日志
* @param args 要记录的日志内容
*/
log(... args: unknown[]): void;
/**
* 写warn日志
* @param args 要记录的日志内容
*/
warn(... args: unknown[]): void;
}
declare class FileSystemManager {
/**
* 重命名文件,可以把文件从 oldPath 移动到 newPath
*/
rename(param: wx.types.RenameParams): void;
/**
* FileSystemManager.rename 的同步版本
* @param oldPath 源文件路径,可以是普通文件或目录
* @param newPath 新文件路径
* @throws 指定源文件或目标文件没有写权限
* @throws 源文件不存在,或目标文件路径的上层目录不存在
*/
renameSync(oldPath: string, newPath: string): void;
/**
* 删除目录
*/
rmdir(param: wx.types.RmdirParams): void;
/**
* rmdir 的同步版本
* @param dirPath 要删除的目录路径
* @param recursive 是否递归删除目录。如果为 true,则删除该目录和该目录下的所有子目录以及文件。
* @throws 目录不存在, 目录不为空, 指定的 dirPath 路径没有写权限
*/
rmdirSync(dirPath: string, recursive?: boolean): void;
/**
* 读取目录内文件列表
*/
readdir(param: wx.types.ReaddirParams): void;
/**
* readdir的同步版本
* @param dirPath 要读取的目录路径
* @throws 目录不存在
* @throws dirPath 不是目录
* @throws 指定的 filePath 路径没有读权限
*/
readdirSync(dirPath: string): ReadonlyArray<string>;
/**
* 创建目录
*/
mkdir(param: wx.types.MkdirParams): void;
/**
* mkdir 的同步版本
* @param dirPath 创建的目录路径
* @param recursive 是否在递归创建该目录的上级目录后再创建该目录。如果对应的上级目录已经存在,则不创建该上级目录。如 dirPath 为 a/b/c/d 且 recursive 为 true,将创建 a 目录,再在 a 目录下创建 b 目录,以此类推直至创建 a/b/c 目录下的 d 目录。
* @throws 上级目录不存在
* @throws 指定的 filePath 路径没有写权限
* @throws 有同名文件或目录
*/
mkdirSync(dirPath: string, recursive?: boolean): void;
/**
* 解链文件
*/
unlink(param: wx.types.UnlinkParams): void;
/**
* unlink 的同步版本
* @param filePath 要解链的文件路径
* @throws 指定的 path 路径没有读权限
* @throws 文件不存在
* @throws 传入的 filePath 是一个目录
*/
unlinkSync(filePath: string): void;
/**
* 解压文件
*/
unzip(param: wx.types.UnzipParams): void;
/**
* 读取本地文件内容
*/
readFile(param: wx.types.ReadfileParams): void;
/**
* readFile 的同步版本,读取并返回指定路径的文件的原始二进制内容
* @param filePath 要读取的文件的路径
* @throws 指定的 filePath 所在目录不存在
* @throws 指定的 filePath 路径没有读权限
*/
readFileSync(filePath: string): ArrayBuffer;
/**
* readFile 的同步版本,读取并按指定字符编码返回字符串
* @param filePath 要读取的文件的路径
* @param encoding 指定读取文件的字符编码
* @throws 指定的 filePath 所在目录不存在
* @throws 指定的 filePath 路径没有读权限
*/
readFileSync(filePath: string, encoding: wx.types.FileContentEncoding): string;
/**
* 获取文件 Stats 对象
*/
stat(param: wx.types.StatParams): void;
/**
* stat 的同步版本
* @param path 文件/目录路径
* @throws 指定的 path 路径没有读权限
* @throws 文件不存在
*/
statSync(path: string): Stats;
/**
* 写文件
*/
writeFile(param: wx.types.WritefileParams): void;
/**
* writeFile 的同步版本,写入二进制原始文件数据
* @param filePath 要写入的文件路径
* @param data 要写入的二进制数据
* @throws 指定的 filePath 所在目录不存在
* @throws 指定的 filePath 路径没有写权限
*/
writeFileSync(filePath: string, data: ArrayBuffer): void;
/**
* writeFile 的同步版本,写入文本字符串数据至文件
* @param filePath 要写入的文件路径
* @param data 要写入的文本内容
* @param encoding 指定写入的文本的字符编码格式
* @throws 指定的 filePath 所在目录不存在
* @throws 指定的 filePath 路径没有写权限
*/
writeFileSync(filePath: string, data: string, encoding: wx.types.FileContentEncoding): void;
/**
* 判断文件/目录是否存在
*/
access(param: wx.types.AccessfileParams): void;
/**
* access的同步版本
* @param path 要判断是否存在的文件/目录路径
* @throws 文件/目录不存在
*/
accessSync(path: string): void;
/**
* 复制文件
*/
copyFile(param: wx.types.CopyfileParams): void;
/**
* copyFile 的同步版本
* @param srcPath 源文件路径,只可以是普通文件
* @param destPath 目标文件路径
* @throws 指定目标文件路径没有写权限
* @throws 源文件不存在,或目标文件路径的上层目录不存在
*/
copyFileSync(srcPath: string, destPath: string): void;
/**
* 获取该小程序下已保存的本地缓存文件列表
* @param res.fileList.filePath 本地路径
* @param res.fileList.size 本地文件大小,以字节为单位
* @param res.fileList.createTime 文件创建时间
*/
getSavedFileList(param: wx.types.CallbacksWithType<wx.types.SavedfileList>): void;
/**
* 获取该小程序下的 本地临时文件 或 本地缓存文件 信息
*/
getFileInfo(param: wx.types.FileinfoParams): void;
/**
* 删除该小程序下已保存的本地缓存文件(新版本应使用unlink)
*/
removeSavedFile(param: wx.types.RemovefileParams): void;
/**
* 保存临时文件到本地。此接口会移动临时文件,因此调用成功后,tempFilePath 将不可用。
*/
saveFile(param: wx.types.SavefileParams): void;
/**
* saveFile的同步版本
* @param tempFilePath 临时存储文件路径
* @param filePath 要存储的文件路径
* @throws 指定的 tempFilePath 找不到文件
* @throws 指定的 filePath 路径没有写权限
* @throws 上级目录不存在
*/
saveFileSync(tempFilePath: string, filePath?: string): string;
/**
* 在文件结尾追加内容
*/
appendFile(param: wx.types.AppendfileParams): void;
/**
* appendFile的同步版本
* @param filePath 要追加内容的文件路径
* @param data 要追加的文本或二进制数据
* @param encoding 指定写入文件的字符编码
* @throws 指定的 filePath 文件不存在
* @throws 指定的 filePath 是一个已经存在的目录
* @throws 指定的 filePath 路径没有写权限
* @throws 指定的 filePath 是一个已经存在的目录
*/
appendFileSync(filePath: string, data: string | ArrayBuffer, encoding: wx.types.FileContentEncoding): void;
}
declare class DownloadTask {
/**
* 中断下载任务
*/
abort(): void;
/**
* 监听下载进度变化事件
* @param res.progress 下载进度百分比,值为0至100
* @param res.totalBytesWritten 已经下载的数据长度,单位 Bytes
* @param res.totalBytesExpectedToWrite 预期需要下载的数据总长度,单位 Bytes
*/
onProgressUpdate(callback: (res: { progress: number, totalBytesWritten: number, totalBytesExpectedToWrite: number }) => void): void;
}
declare class RequestTask {
/**
* 中断请求任务
*/
abort(): void;
}
declare class SocketTask {
/**
* 通过WebSocket发送数据
*/
send(param: wx.types.SocketSendParams): void;
/**
* 关闭WebSocket连接
*/
close(param: wx.types.SocketCloseParams): void;
/**
* 监听WebSocket 连接打开事件
*/
onOpen(callback: wx.types.SocketOpenCallback): void;
/**
* 监听WebSocket 连接关闭事件
*/
onClose(callback: () => void): void;
/**
* 监听WebSocket 错误事件
*/
onError(callback: wx.types.SocketErrorCallback): void;
/**
* 监听WebSocket 接受到服务器的消息事件
*/
onMessage(callback: wx.types.SocketMessageCallback): void;
}
/**
* 一个 UDP Socket 实例,默认使用 IPv4 协议。
* 错误码:
* -1 系统错误
* -2 socket接口错误
* -3 发送失败,无接口权限
* 1 发送失败,参数错误,address不合法
* 2 发送失败,参数错误,port不合法
*/
declare class UDPSocket {
/**
* 绑定一个系统随机分配的可用端口,或绑定一个指定的端口号
* @param port 需要绑定的端口号,不指定时使用随机端口
* @returns 绑定成功的端口号
*/
bind(port?: number): number;
/**
* 向指定的 IP 和 port 发送消息
*/
send(param: wx.types.UDPSendParams): void;
/**
* 关闭 UDP Socket 实例,相当于销毁。 在关闭之后,UDP Socket 实例不能再发送消息,每次调用 UDPSocket.send 将会触发错误事件,
* 并且 message 事件回调函数也不会再执行。在 UDPSocket 实例被创建后将被 Native 强引用,保证其不被 GC。在 UDPSocket.close 后
* 将解除对其的强引用,让 UDPSocket 实例遵从 GC。
*/
close(): void;
/**
* 设置监听关闭事件回调
* @param callback 关闭事件的回调函数
*/
onClose(callback: () => void): void;
/**
* 清除监听关闭事件回调
* @param callback 之前监听的函数
*/
offClose(callback: () => void): void;
/**
* 监听错误事件
* @param callback 错误回调函数
*/
onError(callback: (res: {
/**
* 错误信息
*/
errMsg: string;
}) => void): void;
/**
* 取消监听错误事件
* @param callback 之前设置的错误回调函数
*/
offError(callback: (res: {
/**
* 错误信息
*/
errMsg: string;
}) => void): void;
/**
* 监听开始监听数据包消息的事件
* @param callback 回调函数
*/
onListening(callback: () => void): void;
/**
* 取消监听开始监听数据包消息的事件
* @param callback 之前设置的回调函数
*/
offListening(callback: () => void): void;
/**
* 监听收到消息的事件
* @param callback 回调函数
*/
onMessage(callback: (res: wx.types.UDPMessage) => void): void;
/**
* 取消监听收到消息的事件
* @param callback 之前设置的回调函数
*/
offMessage(callback: (res: wx.types.UDPMessage) => void): void;
}
declare class UploadTask {
/**
* 中断上传任务
*/
abort(): void;
/**
* 监听上传进度变化事件
* @param callback.res.progress 上传进度百分比
* @param callback.res.totalBytesSent 已经上传的数据长度,单位 Bytes
* @param callback.res.totalBytesExpectedToSend 预期需要上传的数据总长度,单位 Bytes
*/
onProgressUpdate(callback: (res: { progress: number, totalBytesSent: number, totalBytesExpectedToSend: number }) => void): void;
}
declare class KVData {
key: string;
value: string;
}
declare class UserGameData {
/**
* 用户的微信头像 url
*/
avatarUrl: string;
/**
* 用户的微信昵称
*/
nickname: string;
/**
* 用户的openid
*/
openid: string;
/**
* 用户的托管 KV 数据列表
*/
KVDataList: ReadonlyArray<KVData>;
}
declare class CreatedButton {
type: wx.types.ButtonType;
text: string;
image: string;
style: wx.types.ButtonStyle;
show(): void;
hide(): void;
onTap(callback: (res?: any) => void): void; // res参数会被具体按钮的API定义覆盖为具体信息
offTap(callback: (res?: any) => void): void;
destroy(): void;
}
declare class UserInfoButton extends CreatedButton {
onTap(callback: (res: {
/**
* 用户信息对象,不包含 openid 等敏感信息
*/
userInfo: wx.types.UserInfo,
/**
* 不包括敏感信息的原始数据字符串,用于计算签名
*/
rawData: string,
/**
* 使用 sha1( rawData + sessionkey ) 得到字符串,用于校验用户信息,参考文档signature(https://mp.weixin.qq.com/debug/wxagame/dev/tutorial/open-ability/http-signature.html?t=201822)
*/
signature: string,
/**
* 包括敏感数据在内的完整用户信息的加密数据,详见加密数据解密算法(https://mp.weixin.qq.com/debug/wxagame/dev/tutorial/open-ability/signature.html?t=201822)
*/
encryptedData: string,
/**
* 加密算法的初始向量,详见加密数据解密算法(https://mp.weixin.qq.com/debug/wxagame/dev/tutorial/open-ability/signature.html?t=201822)
*/
iv: string,
errMsg: string
}) => void): void;
}
declare class OpenSettingButton extends CreatedButton {
onTap(callback: () => void): void;
offTap(callback: () => void): void;
}
declare class GameClubButton extends CreatedButton {
icon: wx.types.GameClubButtonIcon;
onTap(callback: (res: {
errMsg: string;
}) => void): void;
}
declare class FeedbackButton extends CreatedButton {
onTap(callback: (res: {
errMsg: string;
}) => void): void;
}
declare class OpenDataContext {
/**
* 开放数据域和主域共享的 sharedCanvas,注意在开放数据域内时getContext只能使用2d模式
*/
canvas: Canvas;
/**
* 向开放数据域发送消息
* @param message 要发送的消息,message 中及嵌套对象中 key 的 value 只能是 primitive value。即 number、string、boolean、null、undefined。
*/
postMessage(message: any): void;
}
declare class LoadSubpackageTask {
/**
* 监听分包加载进度变化事件
* @param callback.res.progress 分包下载进度百分比
* @param callback.res.totalBytesWritten 已经下载的数据长度,单位 Bytes
* @param callback.res.totalBytesExpectedToWrite 预期需要下载的数据总长度,单位 Bytes
*/
onProgressUpdate(callback: (res: { progress: number, totalBytesWritten: number, totalBytesExpectedToWrite: number }) => void): void;
}
declare class UpdateManager {
/**
* 应用更新包并重启
*/
applyUpdate(): void;
/**
* 监听检查更新结果回调
*/
onCheckForUpdate(callback: () => void): void;
/**
* 监听更新包下载成功回调
*/
onUpdateReady(callback: () => void): void;
/**
* 监听更新包下载失败回调
*/
onUpdateFailed(callback: () => void): void;
}
declare class WxWorker {
/**
* 向主线程或Worker线程发送的消息。
* @param message 需要发送的消息,必须是一个可序列化的 JavaScript 对象。
*/
postMessage(message: any): void;
/**
* 结束当前 worker 线程,仅限在主线程 worker 对象上调用。
*/
terminate(): void;
/**
* 监听接收主线程/Worker 线程向当前线程发送的消息
* @param callback.res.message 接收主线程/Worker 线程向当前线程发送的消息
*/
onMessage(callback: (res: { message: any }) => void): void;
/**
* 监听 worker线程被系统回收事件(当iOS系统资源紧张时,worker线程存在被系统回收的可能,开发者可监听此事件并重新创建一个worker)。仅限在主线程 worker 对象上调用。
*/
onProcessKilled(callback: () => void): void;
}
/**
* InnerAudioContext 实例,可通过 wx.createInnerAudioContext 接口获取实例。
*/
declare class InnerAudioContext {
/**
* 音频资源的地址
*/
src: string;
/**
* 是否自动播放
*/
autoplay: boolean;
/**
* 是否循环播放
*/
loop: boolean;
/**
* 是否遵循系统静音开关,当此参数为 false 时,即使用户打开了静音开关,也能继续发出声音
*/
obeyMuteSwitch: boolean;
/**
* 当前音频的长度,单位 s。只有在当前有合法的 src 时返回
*/
readonly duration: number;
/**
* 当前音频的播放位置,单位 s。只有在当前有合法的 src 时返回,时间不取整,保留小数点后 6 位
*/
readonly currentTime: number;
/**
* 当前是是否暂停或停止状态,true 表示暂停或停止,false 表示正在播放
*/
paused: boolean;
/**
* 音频缓冲的时间点,仅保证当前播放时间点到此时间点内容已缓冲
*/
readonly buffered: number;
/**
* 音量。范围 0~1。
*/
volume: number;
/**
* 播放
*/
play(): void;
/**
* 暂停。暂停后的音频再播放会从暂停处开始播放
*/
pause(): void;
/**
* 停止。停止后的音频再播放会从头开始播放。
*/
stop(): void;
/**
* 跳转到指定位置,单位 s
* @param position 跳转的时间
*/
seek(position: number): void;
/**
* 销毁当前实例
*/
destroy(): void;
/**
* 监听音频进入可以播放状态的事件
*/
onCanplay(callback: () => void): void;
/**
* 取消监听音频进入可以播放状态的事件
*/
offCanplay(callback: () => void): void;
/**
* 监听音频播放事件
*/
onPlay(callback: () => void): void;
/**
* 取消监听音频播放事件
*/
offPlay(callback: () => void): void;
/**
* 监听音频暂停事件
*/
onPause(callback: () => void): void;
/**
* 取消监听音频暂停事件
*/
offPause(callback: () => void): void;
/**
* 监听音频停止事件
*/
onStop(callback: () => void): void;
/**
* 取消监听音频停止事件
*/
offStop(callback: () => void): void;
/**
* 监听音频自然播放至结束的事件
*/
onEnded(callback: () => void): void;
/**
* 取消监听音频自然播放至结束的事件
*/
offEnded(callback: () => void): void;
/**
* 监听音频播放进度更新事件
*/
onTimeUpdate(callback: () => void): void;
/**
* 取消监听音频播放进度更新事件
*/
offTimeUpdate(callback: () => void): void;
/**
* 监听音频播放错误事件
*/
onError(callback: () => void): void;
/**
* 取消监听音频播放错误事件
*/
offError(callback: () => void): void;
/**
* 监听音频加载中事件,当音频因为数据不足,需要停下来加载时会触发
*/
onWaiting(callback: () => void): void;
/**
* 取消监听音频加载中事件,当音频因为数据不足,需要停下来加载时会触发
*/
offWaiting(callback: () => void): void;
/**
* 监听音频进行跳转操作的事件
*/
onSeeking(callback: () => void): void;
/**
* 取消监听音频进行跳转操作的事件
*/
offSeeking(callback: () => void): void;
/**
* 监听音频完成跳转操作的事件
*/
onSeeked(callback: () => void): void;
/**
* 取消监听音频完成跳转操作的事件
*/
offSeeked(callback: () => void): void;
}
declare class RecorderManager {
/**
* 开始录音
*/
start(param: {
/**
* 录音的时长,单位 ms,最大值 600000(10 分钟),默认值60000(1 分钟)
*/
duration?: number | undefined,
/**
* 采样率
*/
sampleRate: 8000 | 11025 | 12000 | 16000 | 22050 | 24000 | 32000 | 44100 | 48000,
/**
* 录音通道数
*/
numberOfChannels: 1 | 2,
/**
* 编码码率
*/
encodeBitRate: number,
/**
* 音频格式
*/
format: "mp3" | "aac",
/**
* 指定帧大小,单位 KB。传入 frameSize 后,每录制指定帧大小的内容后,会回调录制的文件内容,不指定则不会回调
*/
frameSize: number,
/**
* 指定录音的音频源,可通过 wx.getAvailableAudioSources() 获取当前可用的音频源,默认值auto
*/
audioSource?: wx.types.AudioSourceType | undefined
}): void;
/**
* 暂停录音
*/
pause(): void;
/**
* 继续录音
*/
resume(): void;
/**
* 停止录音
*/
stop(): void;
/**
* 监听录音开始事件
*/
onStart(callback: () => void): void;
/**
* 监听录音继续事件
*/
onResume(callback: () => void): void;
/**
* 监听录音暂停事件
*/
onPause(callback: () => void): void;
/**
* 监听录音结束事件
* @param callback.res.tempFilePath 录音文件的临时路径
*/
onStop(callback: (res: { tempFilePath: string }) => void): void;
/**
* 监听已录制完指定帧大小的文件事件。如果设置了 frameSize,则会回调此事件。
* @param callback.res.frameBuffer 录音分片数据
* @param callback.res.isLastFrame 当前帧是否正常录音结束前的最后一帧
*/
onFrameRecorded(callback: (res: { frameBuffer: ArrayBuffer, isLastFrame: boolean }) => void): void;
/**
* 监听录音错误事件
*/
onError(callback: (res: { errMsg: string }) => void): void;
}
declare class ImageFile {
/**
* 本地文件路径
*/
path: string;
/**
* 本地文件大小,单位 B
*/
size: number;
}
declare class Video {
/**
* 视频的左上角横坐标
*/
x: number;
/**
* 视频的左上角纵坐标
*/
y: number;
/**
* 视频的宽度,默认值300
*/
width: number;
/**
* 默认值150
*/
height: number;
/**
* 视频的资源地址
*/
src: string;
/**
* 视频的封面
*/
poster: string;
/**
* 视频的初始播放位置,单位为 s 秒,默认值0
*/
initialTime: number;
/**
* 视频的播放速率,有效值有 0.5、0.8、1.0、1.25、1.5默认值1.0
*/
playbackRate: number;
/**
* 视频是否为直播,默认值0
*/
live?: number | undefined;
/**
* 视频的缩放模式
* fill - 填充,视频拉伸填满整个容器,不保证保持原有长宽比例
* contain - 包含,保持原有长宽比例。保证视频尺寸一定可以在容器里面放得下。因此,可能会有部分空白
* cover - 覆盖,保持原有长宽比例。保证视频尺寸一定大于容器尺寸,宽度和高度至少有一个和容器一致。因此,视频有部分会看不见
*/
objectFit: "contain" | "cover" | "fill";
/**
* 视频是否显示控件,默认true
*/
controls: boolean;
/**
* 视频是否自动播放,默认false
*/
autoplay: boolean;
/**
* 视频是否是否循环播放,默认值false
*/
loop: boolean;
/**
* 视频是否禁音播放,默认值false
*/
muted: boolean;
/**
* 视频开始缓冲时触发的回调函数
*/
onwaiting: () => void;
/**
* 视频开始播放时触发的回调函数
*/
onplay: () => void;
/**
* 视频暂停时触发的回调函数
*/
onpause: () => void;
/**
* 视频播放到末尾时触发的回调函数
*/
onended: () => void;
/**
* 每当视频播放进度更新时触发的回调函数
*/
ontimeupdate: () => void;
/**
* 视频发生错误时触发的回调函数
*/
onerror: () => void;
/**
* 销毁视频
*/
destroy(): void;
/**
* 监听视频缓冲事件
*/
onWaiting(callback: () => void): void;
/**
* 取消监听视频缓冲事件
*/
offWaiting(callback: () => void): void;
/**
* 监听视频播放事件
*/
onPlay(callback: () => void): void;
/**
* 取消监听视频播放事件
*/
offPlay(callback: () => void): void;
/**
* 监听视频暂停事件
*/
onPause(callback: () => void): void;
/**
* 取消监听视频暂停事件
*/
offPause(callback: () => void): void;
/**
* 监听视频播放到末尾事件
*/
onEnded(callback: () => void): void;
/**
* 取消监听视频播放到末尾事件
*/
offEnded(callback: () => void): void;
/**
* 监听视频播放进度更新事件
* @param callback.res.position 当前的播放位置,单位为秒
* @param callback.res.duration 视频的总时长,单位为秒
*/
onTimeUpdate(callback: (res: { position: number, duration: number }) => void): void;
/**
* 取消监听视频播放进度更新事件
*/
offTimeUpdate(callback: (res: { position: number, duration: number }) => void): void;
/**
* 监听视频错误事件
* @param callback.res.errMsg 错误信息,有如下值
* MEDIA_ERR_NETWORK - 当下载时发生错误
* MEDIA_ERR_DECODE - 当解码时发生错误
* MEDIA_ERR_SRC_NOT_SUPPORTED - video 的 src 属性是不支持的资源类型
*/
onError(callback: (res: { errMsg: string }) => void): void;
/**
* 取消监听视频错误事件
*/
offError(callback: (res: { errMsg: string }) => void): void;
/**
* 播放视频
*/
play(): Promise<void>;
/**
* 暂停视频
*/