Update Video Post

Upload videos

If you want to edit a video post to add more videos, the videos to be added must be uploaded first. The AmityFileRepository class handles the uploading and downloading of videos. The repository has an uploadVideo method which takes the video's Uri and returns an array of AmityUploadResult for successful or failed uploads.

AmityUploadResult will return four possible types of data:

  • AmityUploadResult.PROGRESS - uploading is in progress. It returns AmityUploadInfo which can be used to track the progress of the upload.

  • AmityUploadResult.COMPLETE - the upload completed successfully. It returns AmityVideo that can then be attached to the post.

  • AmityUploadResult.ERROR(exception) - the upload failed. It returns an Exception.

  • AmityUploadResult.CANCELLED - uploading is canceled.

fun uploadVideo(videoUri: Uri) {
    AmityCoreClient.newFileRepository()
        .uploadVideo(uri = videoUri)
        .build()
        .transfer()
        .doOnNext{ uploadResult: AmityUploadResult<AmityVideo> ->
            when (uploadResult) {
                is AmityUploadResult.PROGRESS -> {
                    val progress = uploadResult.getUploadInfo().getProgressPercentage()
                }
                is AmityUploadResult.COMPLETE -> {
                    val amityVideo = uploadResult.getFile()
                }
                is AmityUploadResult.ERROR -> {
                    val exception = uploadResult.getError()
                }
                is AmityUploadResult.CANCELLED -> {
                    //proceed
                }
            }
        }
        .subscribe()
}

You can upload a maximum of ten videos in a single post.

Update video post

To edit a video post, use the edit method as shown in the sample code below. The attachments should contain the existing videos and the uploaded videos that you want to add to the post which are stored in existingVideos and newVideos respectively.

You can remove existing videos from the post by excluding them from the attachments list. You can also change the order of the videos in the list.

fun updateVideoPost(post: AmityPost, newVideos: List<AmityVideo>) {
    val postData: AmityPost.Data = post.getData()
    val existingVideos = post?.getChildren()
                    ?.map { it.getData() }
                    ?.filterIsInstance<AmityPost.Data.VIDEO>
    val isVideoPost = existingVideos
                    ?.isNotEmpty() 
                    ?: false
                    
    val attachments = existingVideos + newVideos
    
    if (isVideoPost) {
        postData.edit()
            .attachments(attachments)
            .text(postData.getText())
            .build()
            .apply()
            .subscribe()
    }
 

To update mentioned users in a post, refer to update mention in post.

Last updated