1# @ohos.multimedia.movingphotoview (MovingPhotoView) (System API) 2<!--Kit: Media Library Kit--> 3<!--Subsystem: FileManagement--> 4<!--Owner: @tangye123456--> 5<!--SE: @YanSanzo--> 6<!--TSE: @tinygreyy--> 7 8The **MovingPhotoView** component is used to play moving photos and control the playback status. 9 10> **NOTE** 11> 12> - The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version. 13> - This topic describes only the system APIs provided by the module. For details about its public APIs, see [@ohos.multimedia.movingphotoview (MovingPhotoView)](ohos-multimedia-movingphotoview.md). 14 15## MovingPhotoViewOptions 16 17 18| Name | Type | Mandatory| Description | 19| ----------- | ------------------------------------------------------------------------------------------------ | ---- | ----------------------------------------------------------------------------------------------------------------------------------------------- | 20| movingPhotoFormat<sup>14+</sup> | [PixelMapFormat](#pixelmapformat14) | No | Decoding format of the cover image of the **MovingPhotoView** component. | 21| dynamicRangeMode<sup>14+</sup> | [DynamicRangeMode](#dynamicrangemode14) | No | Range mode of the cover image of the **MovingPhotoView** component.| 22| playWithMask<sup>19+</sup> | boolean | No | Whether the watermark is shown when a moving photo with a watermark is playing.<br>The default value is **false**.<br>**false**: The moving photo fills the component while keeping its aspect ratio; the watermark is hidden.<br>**true**: The watermark is shown.| 23 24## PixelMapFormat<sup>14+</sup> 25 26Enumerates the decoding formats available for the cover image of the **MovingPhotoView** component. 27 28**System API**: This is a system API. 29 30**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 31 32| Name | Value | Description | 33| ---------------------- | ------ | ----------------- | 34| UNKNOWN | 0 | Unknown format.| 35| RGBA_8888 | 1 | RGBA_8888.| 36| NV21 | 2 | NV21.| 37| RGBA_1010102 | 3 | RGBA_1010102.| 38| YCBCR_P010 | 4 | YCBCR_P010.| 39| YCRCB_P010 | 5 | YCRCB_P010.| 40 41## DynamicRangeMode<sup>14+</sup> 42 43Enumerates the extended range modes available for the cover image of the **MovingPhotoView** component. The range mode determines the image display effect. 44 45**System API**: This is a system API. 46 47**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 48 49| Name | Value | Description | 50| ---------------------- | ------ | ----------------- | 51| HIGH | 0 | Enables unrestricted extended range for HDR effects. The recommended decoding format is YCBCR_P010.| 52| CONSTRAINT | 1 | Allows limited extended range for the image content.| 53| STANDARD | 2 | Keeps the image content within the standard dynamic range for SDR effects. The recommended decoding formats are UNKNOWN and RGBA_8888.| 54 55## Example: Setting the Decoding Format and Range Mode for Moving Photos in a System Application 56 57```ts 58// This example illustrates how to use the parameters. For detailed implementation, check the public API documentation for moving photos. 59import { photoAccessHelper, MovingPhotoView, MovingPhotoViewController, MovingPhotoViewAttribute } from '@kit.MediaLibraryKit'; 60import { PixelMapFormat, DynamicRangeMode } from '@ohos.multimedia.movingphotoview'; 61 62let data: photoAccessHelper.MovingPhoto 63async function loading(context: Context) { 64 try { 65 // Ensure that the media assets corresponding to imageFileUri and videoFileUri exist in the application sandbox directory. 66 let imageFileUri = 'file://{bundleName}/data/storage/el2/base/haps/entry/files/xxx.jpg'; 67 let videoFileUri = 'file://{bundleName}/data/storage/el2/base/haps/entry/files/xxx.mp4'; 68 data = await photoAccessHelper.MediaAssetManager.loadMovingPhoto(context, imageFileUri, videoFileUri); 69 console.info('load moving photo successfully'); 70 } catch (err) { 71 console.error(`load moving photo failed with error: ${err.code}, ${err.message}`); 72 } 73} 74@Entry 75@Component 76struct Index { 77 controller: MovingPhotoViewController = new MovingPhotoViewController(); 78 format: undefined | PixelMapFormat = PixelMapFormat.YCBCR_P010; 79 mode: undefined | DynamicRangeMode = DynamicRangeMode.HIGH; 80 private uiContext: UIContext = this.getUIContext() 81 aboutToAppear(): void { 82 loading(this.uiContext.getHostContext()!) 83 } 84 85 build() { 86 NavDestination() { 87 Column() { 88 Stack({ alignContent: Alignment.BottomStart }) { 89 MovingPhotoView({ 90 movingPhoto: data, 91 controller: this.controller, 92 movingPhotoFormat: this.format, 93 dynamicRangeMode: this.mode, 94 playWithMask: false 95 }) 96 } 97 } 98 } 99 } 100} 101``` 102 103## MovingPhotoViewController<sup>12+</sup> 104 105A MovingPhotoViewController object can be used to control a **MovingPhotoView** component. For details, see [Media Module](../apis-media-kit/arkts-apis-media.md). 106 107### pausePlayback<sup>20+</sup> 108 109pausePlayback() 110 111Pauses playback and freezes on the current frame. Once resumed, playback continues right where it left off. 112 113**System API**: This is a system API. 114 115**Atomic service API**: This API can be used in atomic services since API version 20. 116 117**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 118 119**Error codes** 120 121For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 122 123| Error Code| Error Message| 124| -------- | ---------------------------------------- | 125| 202 | Non-system applications are not allowed to use system APIs. | 126 127### reset<sup>20+</sup> 128 129reset() 130 131Returns to the cover frame and rewinds the video. The next play starts from the very beginning. 132 133**System API**: This is a system API. 134 135**Atomic service API**: This API can be used in atomic services since API version 20. 136 137**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 138 139**Error codes** 140 141For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 142 143| Error Code| Error Message| 144| -------- | ---------------------------------------- | 145| 202 | Non-system applications are not allowed to use system APIs. | 146 147### restart<sup>20+</sup> 148 149restart() 150 151Restarts playback from the beginning while keeping the current playback range and mode. 152 153**System API**: This is a system API. 154 155**Atomic service API**: This API can be used in atomic services since API version 20. 156 157**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 158 159**Error codes** 160 161For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 162 163| Error Code| Error Message| 164| -------- | ---------------------------------------- | 165| 202 | Non-system applications are not allowed to use system APIs. | 166 167### setPlaybackPeriod<sup>20+</sup> 168 169setPlaybackPeriod(startTime: double, endTime: double) 170 171Sets the playback range, which takes effect for the next playback. 172 173**System API**: This is a system API. 174 175**Atomic service API**: This API can be used in atomic services since API version 20. 176 177**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 178 179| Name | Type | Mandatory| Description | 180| ------- | ------- | ---- | ---------------------------- | 181| startTime| double| Yes | Start of the range, in ms. The value must be greater than or equal to 0.| 182| endTime| double| Yes | End of the range, in ms. The value must be greater than **startTime**.| 183 184**Error codes** 185 186For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 187 188| Error Code| Error Message| 189| -------- | ---------------------------------------- | 190| 202 | Non-system applications are not allowed to use system APIs. | 191 192### enableTransition<sup>20+</sup> 193 194enableTransition(enabled: boolean) 195 196Enables or disables the zoom-in transition effect when the video starts to play. The setting takes effect for the next playback. 197 198**System API**: This is a system API. 199 200**Atomic service API**: This API can be used in atomic services since API version 20. 201 202**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 203 204| Name | Type | Mandatory| Description | 205| ------- | ------- | ---- | ---------------------------- | 206| enabled| boolean| Yes | Whether to enable the zoom-in transition effect. **true** to enable, **false** otherwise.<br></div>The default value is **true**.| 207 208**Error codes** 209 210For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 211 212| Error Code| Error Message| 213| -------- | ---------------------------------------- | 214| 202 | Non-system applications are not allowed to use system APIs. | 215 216### enableAutoPlay<sup>20+</sup> 217 218enableAutoPlay(enabled: boolean) 219 220Enables or disables the embedded video in a moving photo to play automatically, once. 221 222**System API**: This is a system API. 223 224**Atomic service API**: This API can be used in atomic services since API version 20. 225 226**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 227 228| Name | Type | Mandatory| Description | 229| ------- | ------- | ---- | ---------------------------- | 230| enabled| boolean| Yes | Whether to enable autoplay. **true** to enable, **false** otherwise.<br></div>The default value is **false**.| 231 232**Error codes** 233 234For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 235 236| Error Code| Error Message| 237| -------- | ---------------------------------------- | 238| 202 | Non-system applications are not allowed to use system APIs. | 239