Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion media/livestream/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"name": "google/live-stream-sample",
"type": "project",
"require": {
"google/cloud-video-live-stream": "^0.5.0"
"google/cloud-video-live-stream": "^0.6.0"
}
}
75 changes: 75 additions & 0 deletions media/livestream/src/create_asset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

/**
* Copyright 2023 Google LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* For instructions on how to run the samples:
*
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/livestream/README.md
*/

namespace Google\Cloud\Samples\Media\LiveStream;

// [START livestream_create_asset]
use Google\Cloud\Video\LiveStream\V1\Asset;
use Google\Cloud\Video\LiveStream\V1\Client\LivestreamServiceClient;
use Google\Cloud\Video\LiveStream\V1\CreateAssetRequest;

/**
* Creates an asset. You can use an asset to create a slate.
*
* @param string $callingProjectId The project ID to run the API call under
* @param string $location The location of the asset
* @param string $assetId The ID of the asset to be created
* @param string $assetUri The Cloud Storage URI of the asset
*/
function create_asset(
string $callingProjectId,
string $location,
string $assetId,
string $assetUri
): void {
// Instantiate a client.
$livestreamClient = new LivestreamServiceClient();

$parent = $livestreamClient->locationName($callingProjectId, $location);
$asset = (new Asset())
->setVideo(
(new Asset\VideoAsset())
->setUri($assetUri));

// Run the asset creation request. The response is a long-running operation ID.
$request = (new CreateAssetRequest())
->setParent($parent)
->setAsset($asset)
->setAssetId($assetId);
$operationResponse = $livestreamClient->createAsset($request);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
$result = $operationResponse->getResult();
// Print results
printf('Asset: %s' . PHP_EOL, $result->getName());
} else {
$error = $operationResponse->getError();
// handleError($error)
}
}
// [END livestream_create_asset]

// The following 2 lines are only needed to run the samples
require_once __DIR__ . '/../../../testing/sample_helpers.php';
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
64 changes: 64 additions & 0 deletions media/livestream/src/delete_asset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

/**
* Copyright 2023 Google LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* For instructions on how to run the samples:
*
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/livestream/README.md
*/

namespace Google\Cloud\Samples\Media\LiveStream;

// [START livestream_delete_asset]
use Google\Cloud\Video\LiveStream\V1\Client\LivestreamServiceClient;
use Google\Cloud\Video\LiveStream\V1\DeleteAssetRequest;

/**
* Deletes an asset.
*
* @param string $callingProjectId The project ID to run the API call under
* @param string $location The location of the asset
* @param string $assetId The ID of the asset to be deleted
*/
function delete_asset(
string $callingProjectId,
string $location,
string $assetId
): void {
// Instantiate a client.
$livestreamClient = new LivestreamServiceClient();
$formattedName = $livestreamClient->assetName($callingProjectId, $location, $assetId);

// Run the asset deletion request. The response is a long-running operation ID.
$request = (new DeleteAssetRequest())
->setName($formattedName);
$operationResponse = $livestreamClient->deleteAsset($request);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
// Print status
printf('Deleted asset %s' . PHP_EOL, $assetId);
} else {
$error = $operationResponse->getError();
// handleError($error)
}
}
// [END livestream_delete_asset]

// The following 2 lines are only needed to run the samples
require_once __DIR__ . '/../../../testing/sample_helpers.php';
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
58 changes: 58 additions & 0 deletions media/livestream/src/get_asset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/**
* Copyright 2023 Google LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* For instructions on how to run the samples:
*
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/livestream/README.md
*/

namespace Google\Cloud\Samples\Media\LiveStream;

// [START livestream_get_asset]
use Google\Cloud\Video\LiveStream\V1\Client\LivestreamServiceClient;
use Google\Cloud\Video\LiveStream\V1\GetAssetRequest;

/**
* Gets an asset.
*
* @param string $callingProjectId The project ID to run the API call under
* @param string $location The location of the asset
* @param string $assetId The ID of the asset
*/
function get_asset(
string $callingProjectId,
string $location,
string $assetId
): void {
// Instantiate a client.
$livestreamClient = new LivestreamServiceClient();
$formattedName = $livestreamClient->assetName($callingProjectId, $location, $assetId);

// Get the asset.
$request = (new GetAssetRequest())
->setName($formattedName);
$response = $livestreamClient->getAsset($request);
// Print results
printf('Asset: %s' . PHP_EOL, $response->getName());
}
// [END livestream_get_asset]

// The following 2 lines are only needed to run the samples
require_once __DIR__ . '/../../../testing/sample_helpers.php';
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
58 changes: 58 additions & 0 deletions media/livestream/src/get_pool.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/**
* Copyright 2023 Google LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* For instructions on how to run the samples:
*
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/livestream/README.md
*/

namespace Google\Cloud\Samples\Media\LiveStream;

// [START livestream_get_pool]
use Google\Cloud\Video\LiveStream\V1\Client\LivestreamServiceClient;
use Google\Cloud\Video\LiveStream\V1\GetPoolRequest;

/**
* Gets a pool.
*
* @param string $callingProjectId The project ID to run the API call under
* @param string $location The location of the pool
* @param string $poolId The ID of the pool
*/
function get_pool(
string $callingProjectId,
string $location,
string $poolId
): void {
// Instantiate a client.
$livestreamClient = new LivestreamServiceClient();
$formattedName = $livestreamClient->poolName($callingProjectId, $location, $poolId);

// Get the pool.
$request = (new GetPoolRequest())
->setName($formattedName);
$response = $livestreamClient->getPool($request);
// Print results
printf('Pool: %s' . PHP_EOL, $response->getName());
}
// [END livestream_get_pool]

// The following 2 lines are only needed to run the samples
require_once __DIR__ . '/../../../testing/sample_helpers.php';
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
59 changes: 59 additions & 0 deletions media/livestream/src/list_assets.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

/**
* Copyright 2023 Google LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* For instructions on how to run the samples:
*
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/livestream/README.md
*/

namespace Google\Cloud\Samples\Media\LiveStream;

// [START livestream_list_assets]
use Google\Cloud\Video\LiveStream\V1\Client\LivestreamServiceClient;
use Google\Cloud\Video\LiveStream\V1\ListAssetsRequest;

/**
* Lists the assets for a given location.
*
* @param string $callingProjectId The project ID to run the API call under
* @param string $location The location of the assets
*/
function list_assets(
string $callingProjectId,
string $location
): void {
// Instantiate a client.
$livestreamClient = new LivestreamServiceClient();
$parent = $livestreamClient->locationName($callingProjectId, $location);
$request = (new ListAssetsRequest())
->setParent($parent);

$response = $livestreamClient->listAssets($request);
// Print the asset list.
$assets = $response->iterateAllElements();
print('Assets:' . PHP_EOL);
foreach ($assets as $asset) {
printf('%s' . PHP_EOL, $asset->getName());
}
}
// [END livestream_list_assets]

// The following 2 lines are only needed to run the samples
require_once __DIR__ . '/../../../testing/sample_helpers.php';
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
Loading