Video ready callback

Hi all,

I am uploading a video through PHP API, but I don’t know when the video is ready for view, so the user cannot view yet the video.

Is there any kind of callback(url call) when the video conversion is ready or video is ready for view?

Thanks!

Hello @mappsvid,

There are two ways you can go about this:

  1. Once the upload process concludes, call baseEntry->get() and ensure the status member of the returned object is set to 2 [READY] and, if not, sleep for a while and check again. That’s okay for short [small] source videos but can become inefficient with longer [bigger] sources.

  2. Use the event notifications mechanism to trigger an alert once the entry is ready for playback.
    To learn more about how this mechanism works, see https://developer.kaltura.com/workflows/Integration_Scheduling_and_Hooks/Backend_and_Email_Notifications

Below is a full example for setting up such a notification using the Ruby client, but the same can be done using all the other Kaltura API clients and the tutorial above includes a code generator that can save you a lot of time and effort:

#!/usr/bin/ruby
require 'kaltura'
include Kaltura

if ARGV.length < 6
    puts "Usage: " + __FILE__ + " <partner ID> <admin secret> <service URL> <target URL> <web server basic auth username> <web server basic auth passwd>"
      exit 1
end

partner_id = ARGV[0]
admin_secret  = ARGV[1]
target_url = ARGV[3]
target_username = ARGV[4]
target_passwd = ARGV[5]

config = KalturaConfiguration.new()
config.service_url = ARGV[2]
client = KalturaClient.new(config);
client.ks = client.session_service.start(
      admin_secret,
      "",
      Kaltura::KalturaSessionType::ADMIN,
      partner_id)


filter = KalturaEventNotificationTemplateFilter.new()
filter.type_equal = KalturaEventNotificationTemplateType::HTTP
filter.system_name_equal = 'HTTP_ENTRY_STATUS_EQUALS'
pager = KalturaFilterPager.new()

begin
  results = client.event_notification_template_service.list_templates(filter, pager)
  notification_template_id = results.objects[0].id
rescue Kaltura::KalturaAPIError => e
  puts(__LINE__.to_s + ": Exception Class: #{e.class.name}")
  puts(__LINE__.to_s + ": Exception Message: #{e.message}")
end

begin
  event_notification_template = KalturaHttpNotificationTemplate.new()
  clone_results = client.event_notification_template_service.clone(notification_template_id, event_notification_template)
  new_notification_id = clone_results.id
  event_notification_template = KalturaHttpNotificationTemplate.new()
  event_notification_template.url = target_url
  event_notification_template.method = KalturaHttpNotificationMethod::POST
  event_notification_template.data = KalturaHttpNotificationDataFields.new()
  event_notification_template.authentication_method = KalturaHttpNotificationAuthenticationMethod::BASIC
  event_notification_template.password = target_passwd
  event_notification_template.username = target_username

  begin
    results = client.event_notification_template_service.update(new_notification_id, event_notification_template)
    client.event_notification_template_service.update_status(results.id, KalturaEventNotificationTemplateStatus::ACTIVE)
  rescue Kaltura::KalturaAPIError => e
    puts("Exception Class: #{e.class.name}")
    puts("Exception Message: #{e.message}")
  end

  puts "New notification event ID: " + results.id.to_s
rescue Kaltura::KalturaAPIError => e
  puts(__LINE__.to_s + ": Exception Class: #{e.class.name}")
  puts(__LINE__.to_s + ": Exception Message: #{e.message}")
end

Great! Thanks, I’ll have a look!