1e41f4b71Sopenharmony_ci# Playing Moving Photos with MovingPhotoView 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **MovingPhotoView** component is used to play moving photos and control the playback status. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci## Constraints 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ci- Currently, live properties cannot be set. 8e41f4b71Sopenharmony_ci- Currently, the ArkUI [expandSafeArea](../../reference/apis-arkui/arkui-ts/ts-universal-attributes-expand-safe-area.md#expandsafearea) cannot be set. 9e41f4b71Sopenharmony_ci- When this component is long pressed to trigger playback, the component area is zoomed in to 1.1 times. 10e41f4b71Sopenharmony_ci- This component uses [AVPlayer](../../reference/apis-media-kit/js-apis-media.md#avplayer9) to play moving photos. A maximum of three AVPlayers can be used at the same time. Otherwise, frame freezing may occur. 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci## How to Develop 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ci1. Import modules. 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci ```ts 17e41f4b71Sopenharmony_ci import { MovingPhotoView, MovingPhotoViewController, MovingPhotoViewAttribute } from '@kit.MediaLibraryKit'; 18e41f4b71Sopenharmony_ci ``` 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci2. Obtain a moving photo object. 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci Use the **photoAccessHelper** APIs to create or obtain a moving photo object. The **MovingPhotoView** receives only the constructed moving photo object. 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci For details about how to create and obtain a moving photo object, see [Accessing and Managing Moving Photo Assets](photoAccessHelper-movingphoto.md). 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci ```ts 27e41f4b71Sopenharmony_ci src: photoAccessHelper.MovingPhoto | undefined = undefined; 28e41f4b71Sopenharmony_ci ``` 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci3. Create a **MovingPhotoViewController** instance, which is used to control the playback status of moving photos. 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci ```ts 33e41f4b71Sopenharmony_ci controller: MovingPhotoViewController = new MovingPhotoViewController(); 34e41f4b71Sopenharmony_ci ``` 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci4. Create a **MovingPhotoView** instance. 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci The values in the following sample code are only examples. For details about the value range of each parameter, see [@ohos.multimedia.movingphotoview](../../reference/apis-media-library-kit/ohos-multimedia-movingphotoview.md). 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci ```ts 41e41f4b71Sopenharmony_ci MovingPhotoView({ 42e41f4b71Sopenharmony_ci movingPhoto: this.src, 43e41f4b71Sopenharmony_ci controller: this.controller 44e41f4b71Sopenharmony_ci }) 45e41f4b71Sopenharmony_ci .width('100%') 46e41f4b71Sopenharmony_ci .height('100%') 47e41f4b71Sopenharmony_ci // Whether to mute the playback. The default value is false. In this example, it is controlled by the button. 48e41f4b71Sopenharmony_ci .muted(this.isMuted) 49e41f4b71Sopenharmony_ci // Video display mode, which is set to Contain. The default value is Cover. 50e41f4b71Sopenharmony_ci .objectFit(ImageFit.Contain) 51e41f4b71Sopenharmony_ci // Triggered when the playback starts. 52e41f4b71Sopenharmony_ci .onStart(() => { 53e41f4b71Sopenharmony_ci console.log('onStart') 54e41f4b71Sopenharmony_ci }) 55e41f4b71Sopenharmony_ci // Triggered when the playback ends. 56e41f4b71Sopenharmony_ci .onFinish(() => { 57e41f4b71Sopenharmony_ci console.log('onFinish') 58e41f4b71Sopenharmony_ci }) 59e41f4b71Sopenharmony_ci // Triggered when the playback stops. 60e41f4b71Sopenharmony_ci .onStop(() => { 61e41f4b71Sopenharmony_ci console.log('onStop') 62e41f4b71Sopenharmony_ci }) 63e41f4b71Sopenharmony_ci // Triggered when an error occurs. 64e41f4b71Sopenharmony_ci .onError(() => { 65e41f4b71Sopenharmony_ci console.log('onError') 66e41f4b71Sopenharmony_ci }) 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ci Row() { 69e41f4b71Sopenharmony_ci // Button for starting playback. 70e41f4b71Sopenharmony_ci Button('start') 71e41f4b71Sopenharmony_ci .onClick(() => { 72e41f4b71Sopenharmony_ci this.controller.startPlayback() 73e41f4b71Sopenharmony_ci }) 74e41f4b71Sopenharmony_ci .margin(5) 75e41f4b71Sopenharmony_ci // Button for stopping playback. 76e41f4b71Sopenharmony_ci Button('stop') 77e41f4b71Sopenharmony_ci .onClick(() => { 78e41f4b71Sopenharmony_ci this.controller.stopPlayback() 79e41f4b71Sopenharmony_ci }) 80e41f4b71Sopenharmony_ci .margin(5) 81e41f4b71Sopenharmony_ci // Button controlling whether to mute the playback. 82e41f4b71Sopenharmony_ci Button('mute') 83e41f4b71Sopenharmony_ci .onClick(() => { 84e41f4b71Sopenharmony_ci this.isMuted = !this.isMuted 85e41f4b71Sopenharmony_ci }) 86e41f4b71Sopenharmony_ci .margin(5) 87e41f4b71Sopenharmony_ci } 88e41f4b71Sopenharmony_ci .alignItems(VerticalAlign.Center) 89e41f4b71Sopenharmony_ci .justifyContent(FlexAlign.Center) 90e41f4b71Sopenharmony_ci .height('15%') 91e41f4b71Sopenharmony_ci ``` 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ci## Effect 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ci 96