Expand my Community achievements bar.

Nomination window for the Adobe Community Advisor Program, Class of 2025, is now open!
SOLVED

Fetching thumbnail from brightcove.

Avatar

Level 2

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 ?

1 Accepted Solution

Avatar

Correct answer by
Level 7

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.

View solution in original post

2 Replies

Avatar

Correct answer by
Level 7

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.

Avatar

Community Advisor

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