# Media
# Image
# saveImageToPhotosAlbum
saveImageToPhotosAlbum(Object object)
Saves an image to the system photo album.
Parameters
Object object
| Property | Type | Default Value | Required | Description |
|---|---|---|---|---|
| filePath | string | Yes | Image file path, which can be a temporary file path or a permanent file path. Network image paths are not supported. | |
| success | function | No | Callback function for successful API call | |
| fail | function | No | Callback function for failed API call (When authorization fails, returns error message: fail unauthorized User has not granted read external storage, read/write external storage permissions) | |
| complete | function | No | Callback function for the end of the API call (executed for both success and failure) |
Example Code
ft.saveImageToPhotosAlbum({
filePath: 'finfile://xxxx',
success(res) { }
})
Note
- API Authorization Failure (iOS):
- User denies authorization, returns error message: unauthorized, User has not granted photo album permission
- Host-App prohibits the Mini-Program from actively applying for permissions, returns error message: unauthorized disableauthorized, SDK is prohibited from applying for photo album permission
- API Authorization Failure (Android):
- User denies authorization, returns error message: unauthorized User has not granted read external storage, read/write external storage permissions
- Host-App prohibits the Mini-Program from actively applying for permissions, returns error message: unauthorized disableauthorized SDK is prohibited from actively initiating permission requests
# previewMedia
Preview images and videos.
Parameters
Object object
| Property | Type | Default Value | Required | Description |
|---|---|---|---|---|
| sources | Array.<Object> | Yes | List of resources to preview | |
| current | number | 0 | No | Index of the currently displayed resource |
| showmenu | boolean | true | No | Whether to show the long-press menu. Long-pressing an image shows a menu with options: Send to Friend, Favorite, Save Image, Search, Open Business Card/Go to Group Chat/Open Mini-Program (if the image contains the corresponding QR code or Mini-Program code) |
| success | function | No | Callback function for successful API call | |
| fail | function | No | Callback function for failed API call | |
| complete | function | No | Callback function for the end of the API call (executed for both success and failure) |
Structure of object.sources
| Property | Type | Default Value | Required | Description |
|---|---|---|---|---|
| url | String | Yes | Address of the image or video | |
| type | String | image | No | Type of the resource, default is image |
| poster | string | No | Cover image for the video |
Valid Values for type
| Value | Description | Minimum Version |
|---|---|---|
| image | Image | |
| video | Video |
# previewImage
previewImage(Object object)
Previews images in full screen on a new page.
Parameters
Object object
| Property | Type | Default Value | Required | Description |
|---|---|---|---|---|
| urls | Array.<string> | Yes | List of image links to preview | |
| current | string | First item in urls | No | Link of the currently displayed image |
| success | function | No | Callback function for successful API call | |
| fail | function | No | Callback function for failed API call | |
| complete | function | No | Callback function for the end of the API call (executed for both success and failure) |
Example Code
ft.previewImage({
current: '', // HTTP link of the currently displayed image
urls: [] // List of HTTP links of images to preview
})
# chooseImage
chooseImage(Object object)
Selects images from the local album or takes photos using the camera.
Parameters
Object object
| Property | Type | Default Value | Required | Description |
|---|---|---|---|---|
| count | number | 9 | No | Maximum number of images that can be selected |
| sizeType | Array.<string> | ['original', 'compressed'] | No | Size of the selected images |
| sourceType | Array.<string> | ['album', 'camera'] | No | Source for selecting images |
| success | function | No | Callback function for successful API call | |
| fail | function | No | Callback function for failed API call (When authorization fails, returns error message: fail unauthorized User has not granted read external storage, read/write external storage permissions) | |
| complete | function | No | Callback function for the end of the API call (executed for both success and failure) |
Valid Values for object.sizeType
| Value | Description |
|---|---|
| original | Original image |
| compressed | Compressed image |
Valid Values for object.sourceType
| Value | Description |
|---|---|
| album | Select from album |
| camera | Use camera |
object.success Callback Function
Parameters
Object res
| Property | Type | Description |
|---|---|---|
| tempFilePaths | Array.<string> | List of local temporary file paths of the images |
| tempFiles | Array.<Object> | List of local temporary files of the images |
Structure of res.tempFiles
| Property | Type | Description |
|---|---|---|
| path | string | Local temporary file path |
| size | number | Local temporary file size, in bytes (B) |
Example Code
ft.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success(res) {
// tempFilePath can be used as the src attribute of an img tag to display the image
const tempFilePaths = res.tempFilePaths
}
})
Note
- API Authorization Failure (iOS):
- User denies authorization, returns error message: unauthorized, User has not granted photo album permission
- Host-App prohibits the Mini-Program from actively applying for permissions, returns error message: unauthorized disableauthorized, SDK is prohibited from applying for photo album permission
- API Authorization Failure (Android):
- User denies authorization, returns error message: unauthorized User has not granted read external storage, read/write external storage permissions
- Host-App prohibits the Mini-Program from actively applying for permissions, returns error message: unauthorized disableauthorized SDK is prohibited from actively initiating permission requests
# Video
# createVideoContext
Supported since Base Library 2.11.2, iOS version 2.34.1, Android version 2.34.1 VideoContext ft.createVideoContext(string id, Object this)
Creates a video context VideoContext object.
Parameters
string id
The id of the video component
Object this
In a custom component, the 'this' of the current component instance, used to manipulate the video component within the component
Return Value
VideoContext
# VideoContext Methods
VideoContext.play()
Plays the video
VideoContext.pause()
Pauses the video
VideoContext.stop()
Stops the video
VideoContext.seek(number position)
Seeks to the specified position
position unit: seconds (s)
VideoContext.sendDanmu(Object data)
Sends a danmu (bullet comment)
Parameters
Object data
| Property | Type | Default Value | Required | Description |
|---|---|---|---|---|
| text | string | Yes | Danmu text | |
| color | string | No | Danmu color |
VideoContext.playbackRate(number rate)
Sets the playback rate
Rate value, valid values: 0.5/0.8/1.0/1.25/1.5/2
VideoContext.requestFullScreen(Object object)
Enters full screen (not supported in IDE)
Parameters
Object object
| Property | Type | Default Value | Required | Description |
|---|---|---|---|---|
| direction | number | No | Sets the video orientation in full screen. If not specified, it is automatically determined based on the aspect ratio. Valid values: 0, 90, -90 |
VideoContext.exitFullScreen()
Exits full screen (not supported in IDE)
VideoContext.showStatusBar()
Shows the status bar, only effective in iOS full screen mode.
VideoContext.hideStatusBar()
Hides the status bar, only effective in iOS full screen mode.
VideoContext.requestBackgroundPlayback()
Enters background audio playback mode (not supported in IDE)
VideoContext.exitBackgroundPlayback()
Exits background audio playback mode (not supported in IDE)
# Audio
# setInnerAudioOption
setInnerAudioOption(Object object) Sets the playback options for InnerAudioContext. The settings take effect globally for the current Mini-Program after being set.
Parameters
Object object
| Property | Type | Default Value | Required | Description |
|---|---|---|---|---|
| mixWithOther | boolean | true | No | Whether to mix with other audio. If set to true, it will not terminate the music of other applications or within the Host-App |
| obeyMuteSwitch | boolean | true | No | (Only effective on iOS) Whether to obey the mute switch. If set to false, sound can still be played even in mute mode |
| speakerOn | boolean | true | No | true means play through the speaker, false means play through the earpiece. Default value is true. |
| success | function | No | Callback function for successful API call | |
| fail | function | No | Callback function for failed API call | |
| complete | function | No | Callback function for the end of the API call (executed for both success and failure) |
Note To ensure the overall experience, when speakerOn is true, the client will ignore the mixWithOthers parameter content and forcibly be mutually exclusive with other audio. Switching to speaker playback during audio playback is not supported. If developers need to switch, they can first pause the currently playing audio and record the current pause time point, then switch and resume playback from the original pause time point.
# createInnerAudioContext
InnerAudioContext ft.createInnerAudioContext()
Creates an audio context InnerAudioContext object.
Return Value
InnerAudioContext
# InnerAudioContext
InnerAudioContext instance, obtainable via ft.createInnerAudioContext.
Properties
string src
The address of the audio resource, used for direct playback.number startTime
The position to start playback (unit: s), default is 0boolean autoplay
Whether to start playback automatically, default is falseboolean loop
Whether to loop playback, default is falsenumber volume
Volume. Range 0~1. Default is 1number playbackRate
Playback speed. Range 0.5-2.0, default is 1.
Methods
InnerAudioContext.play()
PlayInnerAudioContext.pause()
Pause. Audio resumed after pausing will start playing from the paused position.InnerAudioContext.stop()
Stop. Audio played after stopping will start from the beginning.InnerAudioContext.seek(number position)
Seek to the specified positionInnerAudioContext.destroy()
Destroy the current instanceInnerAudioContext.onCanplay(function callback)
Listen for the event when the audio enters a playable state. Does not guarantee smooth playback afterwards.
InnerAudioContext.offCanplay(function callback)
Cancel listening for the event when the audio enters a playable stateInnerAudioContext.onPlay(function callback)
Listen for the audio playback eventInnerAudioContext.offPlay(function callback)
Cancel listening for the audio playback eventInnerAudioContext.onPause(function callback)
Listen for the audio pause eventInnerAudioContext.offPause(function callback)
Cancel listening for the audio pause eventInnerAudioContext.onStop(function callback)
Listen for the audio stop eventInnerAudioContext.offStop(function callback)
Cancel listening for the audio stop eventInnerAudioContext.onEnded(function callback)
Listen for the event when audio finishes playing naturallyInnerAudioContext.offEnded(function callback)
Cancel listening for the event when audio finishes playing naturallyInnerAudioContext.onTimeUpdate(function callback)
Listen for the audio playback progress update eventInnerAudioContext.offTimeUpdate(function callback)
Cancel listening for the audio playback progress update eventInnerAudioContext.onError(function callback)
Listen for the audio playback error eventInnerAudioContext.offError(function callback)
Cancel listening for the audio playback error eventInnerAudioContext.onWaiting(function callback)
Listen for the audio loading event. Triggered when audio has to stop to load data due to insufficient data.InnerAudioContext.offWaiting(function callback)
Cancel listening for the audio loading eventInnerAudioContext.onSeeking(function callback)
Listen for the event when an audio seek operation is performedInnerAudioContext.offSeeking(function callback)
Cancel listening for the event when an audio seek operation is performedInnerAudioContext.onSeeked(function callback)
Listen for the event when an audio seek operation is completedInnerAudioContext.offSeeked(function callback)
Cancel listening for the event when an audio seek operation is completed
Example Code
// innerAudioContext.js
const innerAudioContext = wx.createInnerAudioContext()
innerAudioContext.autoplay = true
innerAudioContext.src = 'http://ws.stream.qqmusic.qq.com/M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7&uin=346897220&vkey=6292F51E1E384E061FF02C31F716658E5C81F5594D561F2E88B854E81CAAB7806D5E4F103E55D33C16F3FAC506D1AB172DE8600B37E43FAD&fromtag=46'
innerAudioContext.onPlay(() => {
console.log('Start playing')
})
innerAudioContext.onError((res) => {
console.log(res.errMsg)
console.log(res.errCode)
})
# Recording
# getRecorderManager
RecorderManager ft.getRecorderManager()
Gets the globally unique recording manager RecorderManager
Return Value
RecorderManager
# RecorderManager
Globally unique recording manager
Methods
RecorderManager.start(Object object)
Starts recordingRecorderManager.pause()
Pauses recordingRecorderManager.resume()
Resumes recordingRecorderManager.stop()
Stops recordingRecorderManager.onStart(function callback)
Listens for the recording start eventRecorderManager.onResume(function callback)
Listens for the recording resume eventRecorderManager.onPause(function callback)
Listens for the recording pause eventRecorderManager.onStop(function callback)
Listens for the recording end event
RecorderManager.onError(function callback)
Listens for the recording error eventRecorderManager.onInterruptionBegin(function callback)
Listens for the event when recording is interrupted due to system occupancy. The pause event is triggered after this event.RecorderManager.onInterruptionEnd(function callback)
Listens for the recording interruption end event. After receiving the interruptionBegin event, all recordings within the Mini-Program will pause. Recording can only be successful again after receiving this event.
Note
- API Authorization Failure (iOS):
- User denies authorization, returns error message: unauthorized, User has not granted microphone permission
- Host-App prohibits the Mini-Program from actively applying for permissions, returns error message: unauthorized disableauthorized, SDK is prohibited from applying for microphone permission
# Camera
# createCameraContext
createCameraContext()
Creates a camera context CameraContext object.
Return Value
CameraContext