Create channel event (v1)

Create a new ad break event for a channel.

Code sample

Java

To learn how to install and use the client library for Live Stream API, see Live Stream API client libraries. For more information, see the Live Stream API Java API reference documentation.

To authenticate to Live Stream API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

import com.google.cloud.video.livestream.v1.Event;
import com.google.cloud.video.livestream.v1.LivestreamServiceClient;
import com.google.protobuf.Duration;
import java.io.IOException;

public class CreateEvent {

  public static void main(String[] args) throws Exception {
    String projectId = "example-project-id";
    String locationId = "example-location-id";
    String channelId = "example-channel-id";
    String eventId = "example-event-id";
    createEvent(projectId, locationId, channelId, eventId);
  }

  public static void createEvent(
      String projectId, String locationId, String channelId, String eventId) throws Exception {
    try (LivestreamServiceClient client = LivestreamServiceClient.create()) {
      String parent =
          String.format("projects/%s/locations/%s/channels/%s", projectId, locationId, channelId);

      Duration duration = Duration.newBuilder().setSeconds(30).build();
      Event.AdBreakTask adBreakTask = Event.AdBreakTask.newBuilder().setDuration(duration).build();
      Event event =
          Event.newBuilder()
              .setExecuteNow(true)
              .setAdBreak(adBreakTask)
              .build();

      Event response = client.createEvent(parent, event, eventId);
      System.out.println("Created event: " + response.getName());
    }
  }
}

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.