|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Copyright 2022 Google LLC. |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +/** |
| 20 | + * For instructions on how to run the samples: |
| 21 | + * |
| 22 | + * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/livestream/README.md |
| 23 | + */ |
| 24 | + |
| 25 | +namespace Google\Cloud\Samples\Media\LiveStream; |
| 26 | + |
| 27 | +// [START livestream_create_channel_event] |
| 28 | +use Google\Cloud\Video\LiveStream\V1\LivestreamServiceClient; |
| 29 | +use Google\Cloud\Video\LiveStream\V1\Event; |
| 30 | +use Google\Protobuf\Duration; |
| 31 | + |
| 32 | +/** |
| 33 | + * Creates a channel event. This particular sample inserts an ad break marker. |
| 34 | + * Other event types are supported. |
| 35 | + * |
| 36 | + * @param string $callingProjectId The project ID to run the API call under |
| 37 | + * @param string $location The location of the channel |
| 38 | + * @param string $channelId The ID of the channel |
| 39 | + * @param string $eventId The ID of the channel event |
| 40 | + */ |
| 41 | +function create_channel_event( |
| 42 | + string $callingProjectId, |
| 43 | + string $location, |
| 44 | + string $channelId, |
| 45 | + string $eventId |
| 46 | +): void { |
| 47 | + // Instantiate a client. |
| 48 | + $livestreamClient = new LivestreamServiceClient(); |
| 49 | + |
| 50 | + $parent = $livestreamClient->channelName($callingProjectId, $location, $channelId); |
| 51 | + |
| 52 | + $eventAdBreak = (new Event\AdBreakTask()) |
| 53 | + ->setDuration(new Duration(['seconds' => 30])); |
| 54 | + $event = (new Event()) |
| 55 | + ->setAdBreak($eventAdBreak) |
| 56 | + ->setExecuteNow(true); |
| 57 | + |
| 58 | + // Run the channel event creation request. |
| 59 | + $response = $livestreamClient->createEvent($parent, $event, $eventId); |
| 60 | + // Print results. |
| 61 | + printf('Channel event: %s' . PHP_EOL, $response->getName()); |
| 62 | +} |
| 63 | +// [END livestream_create_channel_event] |
| 64 | + |
| 65 | +// The following 2 lines are only needed to run the samples |
| 66 | +require_once __DIR__ . '/../../../testing/sample_helpers.php'; |
| 67 | +\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv); |
0 commit comments