@dfeidao/atom-wxapp > api_media多媒体类
External module: api_media多媒体类
Index
Functions
- choose_image
- choose_video
- create_camera_context
- create_map_context
- create_video_context
- exit_full_screen
- get_image_info
- pause_audio
- pause_background_audio
- pause_video
- paush_record
- play_background_audio
- play_video
- playback_rate
- preview_image
- request_full_screen
- resume_record
- save_image_to_photos_album
- save_video_to_photos_album
- seek_audio
- seek_video
- send_danmu
- start_background_audio
- start_record
- start_record
- start_record
- stop_audio
- stop_background_audio
- stop_record
- stop_record
- take_photo
Functions
choose_image
▸ choose_image(count?: undefined
| number
, sizeType?: 1
| 2
| 4
, sourceType?: 1
| 2
| 4
): Promise
<object
>
Defined in api/media/choose-image.ts:17
从本地相册选择图片或使用相机拍照
see: 微信官方文档
example:
import choose_image from '@dfeidao/atom-wxapp/api/media/choose-image';
const res = await choose_image(5, 2, 2);
Parameters:
Name | Type | Description |
---|---|---|
Optional count |
undefined | number |
最多可以选择的图片张数,默认9 |
Optional sizeType |
1 | 2 | 4 |
所选的图片的尺寸 original 原图,compressed 压缩图,默认二者都有 |
Optional sourceType |
1 | 2 | 4 |
选择图片的来源 album 从相册选图,camera 使用相机,默认二者都有 |
Returns: Promise
<object
>
choose_video
▸ choose_video(sourceType?: 1
| 2
| 4
, compressed?: undefined
| false
| true
, maxDuration?: undefined
| number
, camera?: “front” | “back”): Promise
<object
>
Defined in api/media/choose-video.ts:18
拍摄视频或从手机相册中选视频
see: 微信官方文档
example:
import choose_video from '@dfeidao/atom-wxapp/api/media/choose-video';
const res = await choose_video(2, true, 30, 'front');
Parameters:
Name | Type | Description |
---|---|---|
Optional sourceType |
1 | 2 | 4 |
选择图片的来源 album 从相册选图,camera 使用相机,默认二者都有 |
Optional compressed |
undefined | false | true |
是否压缩所选择的视频文件, 默认true |
Optional maxDuration |
undefined | number |
拍摄视频最长拍摄时间,单位秒, 默认60 |
Optional camera |
“front” | “back” | 默认拉起的是前置或者后置摄像头。部分 Android 手机下由于系统 ROM 不支持无法生效 back 后置摄像头 front 前置摄像头, 默认back |
Returns: Promise
<object
>
create_camera_context
▸ create_camera_context(): Promise
<CameraContext
>
Defined in api/media/create-camera-context.ts:14
创建 camera 上下文 CameraContext 对象
see: 微信官方文档
example:
import create_camera_context from '@dfeidao/atom-wxapp/api/media/create-camera-context';
const CameraContext = await create_camera_context();
Returns: Promise
<CameraContext
>
create_map_context
▸ create_map_context(mapId: string
): MapContext
Defined in api/media/create-map-context.ts:15
创建 map 上下文 MapContext 对象。
see: 微信官方文档
example:
import create_map_context from '@dfeidao/atom-wxapp/api/media/create-map-context';
const MapContext = create_map_context();
Parameters:
Name | Type |
---|---|
mapId | string |
Returns: MapContext
create_video_context
▸ create_video_context(videoId: string
): Promise
<Object
>
Defined in api/media/create-video-context.ts:15
创建 video 上下文 VideoContext 对象。
see: 微信官方文档
example:
import create_video_context from '@dfeidao/atom-wxapp/api/media/create-video-context';
const VideoContext = create_video_context();
Parameters:
Name | Type | Description |
---|---|---|
videoId | string |
组件的 id |
Returns: Promise
<Object
>
exit_full_screen
▸ exit_full_screen(video_context: VideoContext
): Promise
<Object
>
Defined in api/media/exit-full-screen.ts:16
退出全屏
see: 微信官方文档 create_video_context
example:
import create_video_context from '@dfeidao/atom-wxapp/api/media/create-video-context';
import exit_full_screen from '@dfeidao/atom-wxapp/api/media/exit-full-screen';
const VideoContext = create_video_context();
exit_full_screen(VideoContext);
Parameters:
Name | Type |
---|---|
video_context | VideoContext |
Returns: Promise
<Object
>
get_image_info
▸ get_image_info(src: string
): Promise
<object
>
Defined in api/media/get-image-info.ts:16
获取图片信息
description: 网络图片需先配置download域名才能生效。
see: 微信官方文档
example:
import get_image_info from '@dfeidao/atom-wxapp/api/media/get-image-info';
const res = await get_image_info('./images/photo.png');
Parameters:
Name | Type | Description |
---|---|---|
src | string |
图片的路径,可以是相对路径、临时文件路径、存储文件路径、网络图片路径 |
Returns: Promise
<object
>
pause_audio
▸ pause_audio(fd: IFeidaoAiWeappPage
): void
Defined in api/media/pause-audio.ts:18
暂停录音
see: 微信官方文档
example:
import pause_audio from '@dfeidao/atom-wxapp/api/media/pause-audio';
pause_audio(fd);
Parameters:
Name | Type | Description |
---|---|---|
fd | IFeidaoAiWeappPage |
固定参数 |
Returns: void
pause_background_audio
▸ pause_background_audio(fd: IFeidaoAiWeappPage
): void
Defined in api/media/pause-background-audio.ts:18
暂停音乐
see: 微信官方文档
example:
import pause_background_audio from '@dfeidao/atom-wxapp/api/pause-background-audio';
pause_background_audio(fd);
Parameters:
Name | Type | Description |
---|---|---|
fd | IFeidaoAiWeappPage |
固定参数 |
Returns: void
pause_video
▸ pause_video(video_context: VideoContext
): void
Defined in api/media/pause-video.ts:16
暂停视频
see: 微信官方文档 create_video_context
example:
import create_video_context from '@dfeidao/atom-wxapp/api/media/create-video-context';
const VideoContext = create_video_context();
import pause_video from '@dfeidao/atom-wxapp/api/pause-record';
pause_video(VideoContext);
Parameters:
Name | Type |
---|---|
video_context | VideoContext |
Returns: void
paush_record
▸ paush_record(fd: IFeidaoAiWeappPage
): void
Defined in api/media/pause-record.ts:18
暂停录音
see: [微信官方文档]](https://developers.weixin.qq.com/miniprogram/dev/api/RecorderManager.pause.html)
example:
import paush_record from '@dfeidao/atom-wxapp/api/pause-record';
paush_record(fd);
Parameters:
Name | Type | Description |
---|---|---|
fd | IFeidaoAiWeappPage |
固定参数 |
Returns: void
play_background_audio
▸ play_background_audio(fd: IFeidaoAiWeappPage
, src?: undefined
| string
, startTime?: undefined
| number
, title?: undefined
| string
, epname?: undefined
| string
, singer?: undefined
| string
, coverImgUrl?: undefined
| string
, webUrl?: undefined
| string
): void
Defined in api/media/play-background-audio.ts:12
播放音乐
see: 微信官方文档
Parameters:
Name | Type |
---|---|
fd | IFeidaoAiWeappPage |
Optional src |
undefined | string |
Optional startTime |
undefined | number |
Optional title |
undefined | string |
Optional epname |
undefined | string |
Optional singer |
undefined | string |
Optional coverImgUrl |
undefined | string |
Optional webUrl |
undefined | string |
Returns: void
play_video
▸ play_video(video_context: VideoContext
): void
Defined in api/media/play-video.ts:9
播放视频
see: 微信官方文档
Parameters:
Name | Type |
---|---|
video_context | VideoContext |
Returns: void
playback_rate
▸ playback_rate(video_context: VideoContext
, rate: 0.5
| 0.8
| 1
| 1.25
| 1.5
): Promise
<Object
>
Defined in api/media/playback-rate.ts:9
设置倍速播放
see: 微信官方文档
Parameters:
Name | Type |
---|---|
video_context | VideoContext |
rate | 0.5 | 0.8 | 1 | 1.25 | 1.5 |
Returns: Promise
<Object
>
preview_image
▸ preview_image(urls: string
[], current?: undefined
| string
): Promise
<boolean
>
Defined in api/media/preview-image.ts:10
在新页面中全屏预览图片
description: 预览的过程中用户可以进行保存图片、发送给朋友等操作。
see: 微信官方文档
Parameters:
Name | Type |
---|---|
urls | string [] |
Optional current |
undefined | string |
Returns: Promise
<boolean
>
request_full_screen
▸ request_full_screen(video_context: VideoContext
): void
Defined in api/media/request-full-screen.ts:9
进入全屏
see: 微信官方文档
Parameters:
Name | Type |
---|---|
video_context | VideoContext |
Returns: void
resume_record
▸ resume_record(fd: IFeidaoAiWeappPage
): void
Defined in api/media/resume-record.ts:18
继续录音
see: 微信官方文档
example:
import resume_record from '@dfeidao/atom-wxapp/api/resume-record';
resume_record(fd);
Parameters:
Name | Type | Description |
---|---|---|
fd | IFeidaoAiWeappPage |
固定参数 |
Returns: void
save_image_to_photos_album
▸ save_image_to_photos_album(filePath: string
): Promise
<object
>
Defined in api/media/save-image-to-photos-album.ts:10
保存图片到系统相册
description: 调用前需要 用户授权 scope.writePhotosAlbum
see: 微信官方文档
Parameters:
Name | Type |
---|---|
filePath | string |
Returns: Promise
<object
>
save_video_to_photos_album
▸ save_video_to_photos_album(filePath: string
): Promise
<boolean
>
Defined in api/media/save-video-to-photos-album.ts:10
保存视频到系统相册
description: 调用前需要 用户授权 scope.writePhotosAlbum
see: 微信官方文档
Parameters:
Name | Type |
---|---|
filePath | string |
Returns: Promise
<boolean
>
seek_audio
▸ seek_audio(fd: IFeidaoAiWeappPage
, seek: number
): void
Defined in api/media/seek-audio.ts:12
跳转到指定位置
see: 微信官方文档
Parameters:
Name | Type |
---|---|
fd | IFeidaoAiWeappPage |
seek | number |
Returns: void
seek_video
▸ seek_video(video_context: VideoContext
, position: number
): void
Defined in api/media/seek-video.ts:9
跳转到指定位置
see: 微信官方文档
Parameters:
Name | Type |
---|---|
video_context | VideoContext |
position | number |
Returns: void
send_danmu
▸ send_danmu(video_context: VideoContext
, danmu: object
): void
Defined in api/media/send-danmu.ts:9
发送弹幕
see: 微信官方文档
Parameters:
Name | Type |
---|---|
video_context | VideoContext |
danmu | object |
Returns: void
start_background_audio
▸ start_background_audio(fd: IFeidaoAiWeappPage
, seek: number
): void
Defined in api/media/seek-background-audio.ts:12
跳转到指定位置
see: 微信官方文档
Parameters:
Name | Type |
---|---|
fd | IFeidaoAiWeappPage |
seek | number |
Returns: void
start_record
▸ start_record(ctx: CameraContext
, timeoutCallback?: undefined
| false
| true
): Promise
<object
>
Defined in api/media/camera-start-record.ts:17
开始录音
description: 当主动调用 camera-stop-record 原子操作,或者录音超过1分钟时自动结束录音。当用户离开小程序时,此接口无法调用。
see: 微信官方文档 camera-stop-record create_camera_context
example:
import create_camera_context from '@dfeidao/atom-wxapp/api/media/create-camera-context';
const CameraContext = await create_camera_context();
import start_record from '@dfeidao/atom-wxapp/api/media/camera-start-record';
const res = await start_record(CameraContext, true);
Parameters:
Name | Type |
---|---|
ctx | CameraContext |
Optional timeoutCallback |
undefined | false | true |
Returns: Promise
<object
>
start_record
▸ start_record(fd: IFeidaoAiWeappPage
, src?: undefined
| string
, startTime?: undefined
| number
, autoplay?: undefined
| false
| true
, loop?: undefined
| false
| true
, obeyMuteSwitch?: undefined
| false
| true
): void
Defined in api/media/play-audio.ts:12
播放
see: 微信官方文档
Parameters:
Name | Type |
---|---|
fd | IFeidaoAiWeappPage |
Optional src |
undefined | string |
Optional startTime |
undefined | number |
Optional autoplay |
undefined | false | true |
Optional loop |
undefined | false | true |
Optional obeyMuteSwitch |
undefined | false | true |
Returns: void
start_record
▸ start_record(fd: IFeidaoAiWeappPage
, duration?: undefined
| number
, sampleRate?: 8000
| 11025
| 12000
| 16000
| 22050
| 24000
| 32000
| 44100
| 48000
, numberOfChannels?: undefined
| number
, encodeBitRate?: undefined
| number
, format?: “aac” | “mp3”, frameSize?: undefined
| number
): void
Defined in api/media/start-record.ts:24
开始录音
see: 微信官方文档
example:
import start_record from '@dfeidao/atom-wxapp/api/start-record';
start_record(fd);
Parameters:
Name | Type | Description |
---|---|---|
fd | IFeidaoAiWeappPage |
固定参数 |
Optional duration |
undefined | number |
录音的时长,单位 ms,最大值 600000(10 分钟) |
Optional sampleRate |
8000 | 11025 | 12000 | 16000 | 22050 | 24000 | 32000 | 44100 | 48000 |
采样率 8000 11025 12000 16000 22050 24000 32000 44100 48000 |
Optional numberOfChannels |
undefined | number |
录音通道数 1 2 |
Optional encodeBitRate |
undefined | number |
编码码率 |
Optional format |
“aac” | “mp3” | 音频格式 mp3 aac |
Optional frameSize |
undefined | number |
指定帧大小,单位 KB。传入 frameSize 后,每录制指定帧大小的内容后,会回调录制的文件内容,不指定则不会回调。暂仅支持 mp3 格式。 |
Returns: void
stop_audio
▸ stop_audio(fd: IFeidaoAiWeappPage
): void
Defined in api/media/stop-audio.ts:13
停止
description: 停止后的音频再播放会从头开始播放。
see: 微信官方文档
Parameters:
Name | Type |
---|---|
fd | IFeidaoAiWeappPage |
Returns: void
stop_background_audio
▸ stop_background_audio(fd: IFeidaoAiWeappPage
): void
Defined in api/media/stop-background-audio.ts:12
停止音乐
see: 微信官方文档
Parameters:
Name | Type |
---|---|
fd | IFeidaoAiWeappPage |
Returns: void
stop_record
▸ stop_record(ctx: CameraContext
): Promise
<object
>
Defined in api/media/camera-stop-record.ts:16
停止录音
see: 微信官方文档 create_camera_context
example:
import create_camera_context from '@dfeidao/atom-wxapp/api/media/create-camera-context';
const CameraContext = await create_camera_context();
import stop_record from '@dfeidao/atom-wxapp/api/media/camera-stop-record';
const res = await stop_record(CameraContext);
Parameters:
Name | Type |
---|---|
ctx | CameraContext |
Returns: Promise
<object
>
stop_record
▸ stop_record(fd: IFeidaoAiWeappPage
): void
Defined in api/media/stop-record.ts:18
停止录音
see: 微信官方文档
example:
import stop_record from '@dfeidao/atom-wxapp/api/stop-record';
stop_record(fd);
Parameters:
Name | Type | Description |
---|---|---|
fd | IFeidaoAiWeappPage |
固定参数 |
Returns: void
take_photo
▸ take_photo(ctx: CameraContext
, quality?: “high” | “normal” | “low”): Promise
<object
>
Defined in api/media/take-photo.ts:9
拍摄照片
see: 微信官方文档
Parameters:
Name | Type |
---|---|
ctx | CameraContext |
Optional quality |
“high” | “normal” | “low” |
Returns: Promise
<object
>