Query media files based on their OSS URLs

更新时间:
复制 MD 格式

If you don't know a media file's ID — for example, in live-to-VOD scenarios — call the QueryMediaListByURL API operation to look it up by its Object Storage Service (OSS) URL.

<?php

namespace AlibabaCloud\SDK\Sample;

use AlibabaCloud\SDK\Mts\V20140618\Mts;
use \Exception;
use AlibabaCloud\Tea\Exception\TeaError;
use AlibabaCloud\Tea\Utils\Utils;

use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Mts\V20140618\Models\QueryMediaListByURLRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;

class Sample {

    /**
     * Initialize the client using your AccessKey ID and AccessKey secret.
     * @return Mts Client
     */
    public static function createClient(){

        $config = new Config([
                // Required. Set the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable before running this sample.
                "accessKeyId" => getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
                // Required. Set the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable before running this sample.
                "accessKeySecret" => getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
        ]);
        $config->endpoint = "mts.cn-hangzhou.aliyuncs.com";
        return new Mts($config);
    }

    /**
     * @param string[] $args
     * @return void
     */
    public static function main($args){
        $client = self::createClient();
        $queryMediaListByURLRequest = new QueryMediaListByURLRequest([
                // The OSS URL of the media file to query.
                "fileURLs" => "http://example-bucket-****.oss-cn-shanghai.aliyuncs.com/example.mp4",
                // Whether to include playback information in the response.
                "includePlayList" => true,
                // Whether to include snapshot information in the response.
                "includeSnapshotList" => true,
                // Whether to include media information in the response.
                "includeMediaInfo" => true,
                // Whether to include summaries in the response.
                "includeSummaryList" => true
        ]);
        $runtime = new RuntimeOptions([]);
        try {
            // Write your own code to handle the API response.
            $client->queryMediaListByURLWithOptions($queryMediaListByURLRequest, $runtime);
        }
        catch (Exception $error) {
            if (!($error instanceof TeaError)) {
                $error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
            }
            // Handle exceptions carefully in production. The following lines print error details for reference only.
            // Error message.
            var_dump($error->message);
            // Link to the error diagnostics page.
            var_dump($error->data["Recommend"]);
            Utils::assertAsString($error->message);
        }
    }
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
        if (file_exists($path)) {
require_once $path;
}
Sample::main(array_slice($argv, 1));