全部產品
Search
文件中心

ApsaraVideo Media Processing:使用OSS檔案地址查詢媒體檔案

更新時間:Oct 15, 2024

如需擷取媒體ID,可以通過媒體的輸入地址進行媒體資訊的查詢,介面為 QueryMediaListByURL。本文提供使用OSS檔案地址查詢媒體的範例程式碼。

package com.aliyun.sample;

import com.aliyun.tea.*;

public class Sample {

    /**
     * <b>description</b> :
     * <p>使用AK&amp;SK初始化帳號Client</p>
     * @return Client
     *
     * @throws Exception
     */
    public static com.aliyun.mts20140618.Client createClient() throws Exception {

        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // 必填,請確保代碼運行環境設定了環境變數 ALIBABA_CLOUD_ACCESS_KEY_ID。
                .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                // 必填,請確保代碼運行環境設定了環境變數 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
                .setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        config.endpoint = "mts.cn-qingdao.aliyuncs.com";
        return new com.aliyun.mts20140618.Client(config);
    }

    public static void main(String[] args_) throws Exception {
        java.util.List<String> args = java.util.Arrays.asList(args_);
        com.aliyun.mts20140618.Client client = Sample.createClient();
        com.aliyun.mts20140618.models.QueryMediaListByURLRequest queryMediaListByURLRequest = new com.aliyun.mts20140618.models.QueryMediaListByURLRequest()
                //需要查詢的媒體檔案地址
                .setFileURLs("http://example-bucket-****.oss-cn-shanghai.aliyuncs.com/example.mp4")
                //返回結果中是否包含播放資訊
                .setIncludePlayList(true)
                //返回結果中是否包含截圖資訊
                .setIncludeSnapshotList(true)
                //返回結果中是否包含媒體資訊
                .setIncludeMediaInfo(true)
                //返回結果中是否包含摘要列表
                .setIncludeSummaryList(true);
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            // 複製代碼運行請自行列印 API 的傳回值
            client.queryMediaListByURLWithOptions(queryMediaListByURLRequest, runtime);
        } catch (TeaException error) {
            // 此處僅做列印展示,請謹慎對待異常處理,在工程專案中切勿直接忽略異常。
            // 錯誤 message
            System.out.println(error.getMessage());
            // 診斷地址
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // 此處僅做列印展示,請謹慎對待異常處理,在工程專案中切勿直接忽略異常。
            // 錯誤 message
            System.out.println(error.getMessage());
            // 診斷地址
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
    }
}