Fetching thumbnail from brightcove. | Community
Skip to main content
Level 2
January 27, 2025
Solved

Fetching thumbnail from brightcove.

  • January 27, 2025
  • 2 replies
  • 642 views

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 ?

Best answer by AmitVishwakarma

Yes, you can fetch a Brightcove video thumbnail in Java by using Brightcove's REST API.

  • Use Brightcove API: Make a GET request to this endpoint [Include your OAuth token for authentication]: GET https://cms.api.brightcove.com/v1/accounts/{accountId}/videos/{videoId}
  • Extract Thumbnail URL: Parse the JSON response to get the thumbnail URL.
  • Java Example: Use HttpURLConnection (or a library like Apache HttpClient) to call the API, then extract the thumbnail URL from the response.

2 replies

AmitVishwakarma
Community Advisor
AmitVishwakarmaCommunity AdvisorAccepted solution
Community Advisor
January 27, 2025

Yes, you can fetch a Brightcove video thumbnail in Java by using Brightcove's REST API.

  • Use Brightcove API: Make a GET request to this endpoint [Include your OAuth token for authentication]: GET https://cms.api.brightcove.com/v1/accounts/{accountId}/videos/{videoId}
  • Extract Thumbnail URL: Parse the JSON response to get the thumbnail URL.
  • Java Example: Use HttpURLConnection (or a library like Apache HttpClient) to call the API, then extract the thumbnail URL from the response.
Shiv_Prakash_Patel
Community Advisor
Community Advisor
January 27, 2025

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,

Shiv Prakash