All Products
Search
Document Center

ApsaraVideo Media Processing:Query media files based on their OSS URLs

Last Updated:Nov 15, 2024

If you want to obtain the ID of a media file, you can call the QueryMediaListByURL operation to query the information about a media file base on its Object Storage Service (OSS) URL. This topic provides an example on how to use ApsaraVideo Media Processing (MPS) SDK for Java to query media files.

package com.aliyun.sample;

import com.aliyun.tea.*;

public class Sample {

    /**
     * <b>description</b> :
     * <p>Use your AccessKey ID and AccessKey secret to initialize the 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()
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured. 
                .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured. 
                .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()
                // The URL of the media file to be queried.
                .setFileURLs("http://example-bucket-****.oss-cn-shanghai.aliyuncs.com/example.mp4")
                // Specify whether to include playback information in the response.
                .setIncludePlayList(true)
                // Specify whether to include snapshot information in the response.
                .setIncludeSnapshotList(true)
                // Specify whether to include media information in the response.
                .setIncludeMediaInfo(true)
                // Specify whether to include summaries in the response.
                .setIncludeSummaryList(true);
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            // Write your own code to display the response of the API operation if necessary.
            client.queryMediaListByURLWithOptions(queryMediaListByURLRequest, runtime);
        } catch (TeaException error) {
            // Handle exceptions with caution in actual business scenarios and never ignore exceptions in your project. In this example, error messages are displayed for reference only. 
            // The error message.
            System.out.println(error.getMessage());
            // The URL of the corresponding error diagnostics page.
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // Handle exceptions with caution in actual business scenarios and never ignore exceptions in your project. In this example, error messages are displayed for reference only. 
            // The error message.
            System.out.println(error.getMessage());
            // The URL of the corresponding error diagnostics page.
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
    }
}