Hey ,
i have a requirement where in a component i have dialogues to enter Brightcove Player Id, Brightcove Video Id and Brightcove Account Id
now in the backend like ata the model class level i just need to read these value and fetch thumbnail for this video,
its is possible to do that in java code ?
Solved! Go to Solution.
Views
Replies
Total Likes
Yes, you can fetch a Brightcove video thumbnail in Java by using Brightcove's REST API.
Views
Replies
Total Likes
Yes, you can fetch a Brightcove video thumbnail in Java by using Brightcove's REST API.
Views
Replies
Total Likes
Hi @Mohit3
Yes, you can fetch the Brightcove video thumbnail in your Java code by leveraging the Brightcove CMS API. Here's how you can implement it:
Use Sling Models to inject dialog values, call the Brightcove CMS API with Account ID and Video ID using HttpClient, and parse the response to extract the thumbnail_url.
Sling Model Integration
@Model(adaptables = Resource.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class BrightcoveModel {
@Inject
private String brightcovePlayerId;
@Inject
private String brightcoveVideoId;
@Inject
private String brightcoveAccountId;
@Inject
private BrightcoveThumbnailService thumbnailService;
public String getThumbnailUrl() {
String accessToken = "your-access-token"; // Replace with valid token
return thumbnailService.fetchThumbnailUrl(brightcoveAccountId, brightcoveVideoId, accessToken);
}
}
Service to Fetch Thumbnail
public class BrightcoveThumbnailService {
private static final String API_URL_TEMPLATE = "https://cms.api.brightcove.com/v1/accounts/%s/videos/%s";
public String fetchThumbnailUrl(String accountId, String videoId, String accessToken) {
String apiUrl = String.format(API_URL_TEMPLATE, accountId, videoId);
try (CloseableHttpClient client = HttpClients.createDefault()) {
HttpGet request = new HttpGet(apiUrl);
request.setHeader("Authorization", "Bearer " + accessToken);
HttpResponse response = client.execute(request);
String jsonResponse = new String(response.getEntity().getContent().readAllBytes());
JSONObject json = new JSONObject(jsonResponse);
return json.optString("thumbnail_url"); // Extract thumbnail URL
} catch (Exception e) {
throw new RuntimeException("Failed to fetch thumbnail URL", e);
}
}
}
Dynamically fetch the Brightcove thumbnail URL via a service, ensuring clean logic and seamless integration with AEM's Sling Model architecture.
Regards,
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Like
Replies
Views
Likes
Replies
Views
Likes
Replies