Hi All,
I've created the custom video component using sling model from scratch to get videos from DAM itself.When I'm adding the video component.need to select the path of that video.Once it's selected, The component is showing, But the video is not rendering in the page. When I've inspected the page, the VideoUrl is not getting and also attached the screenshot of that. I've given DAM_PATH="/content/dam"
Here is the HTL Script ,Component Definition and Java methods for getting Video Asset given below.
<!-- Component Definition -->
<videoAssetPath
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/pathfield"
emptyText="Select the Video Asset from DAM"
fieldLabel="Video Asset"
name="./videoAssetPath"
required="{Boolean}true"/>
<!--/* videocomponent.html */-->
<div data-sly-use.model="com.adobe.aem.guides.wknd.core.models.VideoComponentModel" data-sly-unwrap>
<video controls>
<source src="${model.videoUrl}" type="video/mp4">
</video>
</div>
<sly data-sly-call="${placeholder @ isEmpty=true}"></sly>

<!--Java methods -->
public VideoComponentModel(Resource resource) {
this.resource = resource;
}
// Method to get video URL
public String getVideoUrl() {
Asset videoAsset = getVideoAsset();
if (videoAsset != null) {
Rendition originalRendition = videoAsset.getOriginal();
return originalRendition != null ? originalRendition.getPath() : "";
}
return "";
}
// Helper method to get the video asset
private Asset getVideoAsset() {
ResourceResolver resolver = resource.getResourceResolver();
// Assuming your video is stored under /content/dam, adjust the path accordingly
String videoPath = DAM_PATH + resource.getPath(); // Use your specific DAM path
// Use the resolver to get the Asset
return resolver.getResource(videoPath).adaptTo(Asset.class);
}
Provide suggestions on this.