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](https://docs.cloud.google.com/livestream/docs/reference/libraries.md.txt).


For more information, see the
[Live Stream API Java API
reference documentation](https://docs.cloud.google.com/java/docs/reference/google-cloud-live-stream/latest/overview).


To authenticate to Live Stream API, set up Application Default Credentials.
For more information, see

[Set up authentication for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment.md.txt).

```java
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](https://docs.cloud.google.com/docs/samples.md.txt?product=livestreamapi).