腾讯云 云点播 JAVASDK上传

maven

<dependency>
            <groupId>com.qcloud</groupId>
            <artifactId>vod_api</artifactId>
            <version>2.1.5</version>
            //如果项目无slf4j-log4j12和cos_api不需要增加此代码
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-log4j12</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.qcloud</groupId>
                    <artifactId>cos_api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

服务器上传

public static String uploadFile(MultipartFile multipartFile) {
        try {


            //生成文件名
            String fileName = UUID.randomUUID().toString() + StrPool.DOT + FilenameUtils.getExtension(multipartFile.getOriginalFilename());

            String tenant = BaseContextHandler.getTenant();

            //日期文件夹
            String relativePath = Paths.get(tenant, LocalDate.now().format(DateTimeFormatter.ofPattern(DEFAULT_MONTH_FORMAT_SLASH))).toString();
            // web服务器存放的绝对路径
            String absolutePath = Paths.get("/data/projects/uploadfile/file/", relativePath).toString();

            java.io.File outFile = new java.io.File(Paths.get(absolutePath, fileName).toString());
            org.apache.commons.io.FileUtils.writeByteArrayToFile(outFile, multipartFile.getBytes());

            String url = new StringBuilder("")
                    .append(absolutePath)
                    .append(StrPool.SLASH)
                    .append(fileName)
                    .toString();
            //替换掉windows环境的\路径
            url = StrUtil.replace(url, "\\\\", StrPool.SLASH);
            url = StrUtil.replace(url, "\\", StrPool.SLASH);
            //url用来获取上传文件的本地位置
            return url;
        } catch (CosClientException e){
            e.printStackTrace();
            throw new BizException(e.getMessage());
        } catch (IOException e) {
            e.printStackTrace();
            throw new BizException(e.getMessage());
        }
    }

简单上传
https://cloud.tencent.com/document/product/266/10276

	//url为本地文件URL地址
    public static VodUploadResponse simpleUpload(String url) {
        // 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
        // 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
        VodUploadClient client = new VodUploadClient("secretId", "secretKey");
        VodUploadRequest request = new VodUploadRequest();
        //任务流名称 如果不走任务流会播放器会出现 1005错误
        request.setProcedure("LongVideoPreset");
        //本地视频地址
        request.setMediaFilePath("C:\\Users\\Administrator\\Videos\\金舟录屏大师\\jzrecord_2020-08-28-17-34-54.mp4");
        try {
            VodUploadResponse response = client.upload("ap-guangzhou", request);
            System.out.println("Upload FileId = {"+response.getFileId()+"}");
            return response;
        } catch (Exception e) {
            // 业务方进行异常处理
            System.out.println("Upload Err = {"+e+"}");
            throw new BizException(e.getMessage());
        }
    }
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, shrink-to-fit=no">
        <title>腾讯云视频点播示例</title>
        <!-- 引入播放器 css 文件 -->
        <link href="//cloudcache.tencent-cloud.com/open/qcloud/video/tcplayer/tcplayer.css" rel="stylesheet">
        <!-- 如需在IE8、9浏览器中初始化播放器,浏览器需支持Flash并在页面中引入 -->
        <!--[if lt IE 9]>
        <script src="//cloudcache.tencent-cloud.com/open/qcloud/video/tcplayer/ie8/videojs-ie8.js"></script>
        <![endif]-->
        <!-- 如果需要在 Chrome 和 Firefox 等现代浏览器中通过 H5 播放 HLS 格式的视频,需要在 tcplayer.v4.1.min.js 之前引入 hls.min.0.13.2m.js -->
        <script src="//imgcache.qq.com/open/qcloud/video/tcplayer/libs/hls.min.0.13.2m.js"></script>
        <!-- 引入播放器 js 文件 -->
        <script src="//imgcache.qq.com/open/qcloud/video/tcplayer/tcplayer.v4.1.min.js"></script>
        <!-- 示例 CSS 样式可自行删除 -->
    </head>
    <body>
        <!-- 设置播放器容器 -->
        <video id="player-container-id" preload="auto" width="1080" height="1920" playsinline webkit-playsinline x5-playsinline></video>
        <!--
        注意事项:
        * 播放器容器必须为 video 标签
        * player-container-id 为播放器容器的ID,可自行设置
        * 播放器区域的尺寸请按需设置,建议通过 css 进行设置,通过css可实现容器自适应等效果
        * playsinline webkit-playsinline x5-playsinline 这几个属性是为了在标准移动端浏览器不劫持视频播放的情况下实现行内播放,此处仅作示例,请按需使用
        -->
        <script>
            var player = TCPlayer("player-container-id", { // player-container-id 为播放器容器ID,必须与html中一致
                fileID: "fileID", // 请传入需要播放的视频fileID 必须
                appID: "appID", // 请传入点播账号的子应用appID 必须
                autoplay: false //是否自动播放
                //其他参数请在开发文档中查看
            });
        </script>
    </body>
</html>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值