其他分享
首页 > 其他分享> > 2、阿里云视屏上传一直显示上传中解决方式

2、阿里云视屏上传一直显示上传中解决方式

作者:互联网

开始用课程1.4.11的jar包依赖加载不出来因为这个版本未开源,所有在使用官方测试代码上传会一直显示上传中

   <aliyun-java-vod-upload.version>1.4.14</aliyun-java-vod-upload.version>
        <aliyun-sdk-vod-upload.version>1.4.14</aliyun-sdk-vod-upload.version>

解决方式(官方图片)

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

mvn install:install-file -DgroupId=com.aliyun -DartifactId=aliyun-sdk-vod-upload -Dversion=1.4.14 -Dpackaging=jar -Dfile=aliyun-java-vod-upload-1.4.14.jar

   <dependency>
        <groupId>com.aliyun</groupId>
        <artifactId>aliyun-java-sdk-core</artifactId>
        <version>4.5.1</version>
    </dependency>
    <dependency>
        <groupId>com.aliyun.oss</groupId>
        <artifactId>aliyun-sdk-oss</artifactId>
        <version>3.10.2</version>
    </dependency>
     <dependency>
        <groupId>com.aliyun</groupId>
        <artifactId>aliyun-java-sdk-vod</artifactId>
        <version>2.15.11</version>
    </dependency>
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>fastjson</artifactId>
        <version>1.2.28</version>
    </dependency>
    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20170516</version>
    </dependency>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.8.2</version>
    </dependency>

自己需要改一个是父工程中对官方要求的两个版本进行修改
在这里插入图片描述
在这里插入图片描述

自己写两个函数实现

第一个

package com.atguigu.vodtest;

import com.aliyun.vod.upload.impl.UploadVideoImpl;
import com.aliyun.vod.upload.req.UploadVideoRequest;
import com.aliyun.vod.upload.resp.UploadVideoResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.vod.model.v20170321.GetPlayInfoRequest;
import com.aliyuncs.vod.model.v20170321.GetPlayInfoResponse;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthRequest;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthResponse;

import java.util.List;

/**
 * @Description:
 * @Author: a寕
 * @Date:2021/8/3 19:03
 */
public class TestVoid {
    public static void main(String[] args) throws ClientException{
        //正式上传代码
        String accessKeyId="LTAI5tPXiqX";
        String accessKeySecret="pch7S3xU4otLB";
        String title="6 - What If I Want to Move Faster";//上传之后文件名称
        String fileName="E:/6 - What If I Want to Move Faster.mp4";//本地文件路径和名称
        UploadVideoRequest request = new UploadVideoRequest(accessKeyId, accessKeySecret, title, fileName);
        /* 可指定分片上传时每个分片的大小,默认为2M字节 */
        request.setPartSize(2 * 1024 * 1024L);
        /* 可指定分片上传时的并发线程数,默认为1,(注:该配置会占用服务器CPU资源,需根据服务器情况指定)*/
        request.setTaskNum(1);
        // request.setEcsRegionId("cn-shanghai");
        UploadVideoImpl uploader = new UploadVideoImpl();
        UploadVideoResponse response = uploader.uploadVideo(request);
        if (response.isSuccess()) {
            System.out.print("VideoId=" + response.getVideoId() + "\n");
        } else {
            /* 如果设置回调URL无效,不影响视频上传,可以返回VideoId同时会返回错误码。其他情况上传失败时,VideoId为空,此时需要根据返回错误码分析具体错误原因 */
            System.out.print("VideoId=" + response.getVideoId() + "\n");
            System.out.print("ErrorCode=" + response.getCode() + "\n");
            System.out.print("ErrorMessage=" + response.getMessage() + "\n");
        }
    }

    //2、根据视屏id获取视屏播放凭证
    public static void getPlayAuth() throws ClientException {

        //创建初始化对象
        DefaultAcsClient client=InitObject.initVodClient("LTAI5tPXiq","pch7S3xU4o");
        //创建获取视屏地址request和response
        GetVideoPlayAuthRequest request=new GetVideoPlayAuthRequest();
        GetVideoPlayAuthResponse response=new GetVideoPlayAuthResponse();
        //向request设置视屏id
        request.setVideoId("1f8729d683fc452cb7b45569a5095f6a");
        //调用初始化对象得到凭证
        response=client.getAcsResponse(request);
        System.out.println("playauth:"+response.getPlayAuth());
    }

    //1、根据视屏id获取视屏播放地址
    public static void getPlayUrl() throws ClientException{
        //创建初始化对象
        DefaultAcsClient client=InitObject.initVodClient("LTAI5tPXiq","pch7S3xU4otLBb");
        //创建获取视屏地址request和response
        GetPlayInfoRequest request=new GetPlayInfoRequest();
        GetPlayInfoResponse response=new GetPlayInfoResponse();
        //向request对象里面设置视屏id
        request.setVideoId("1f8729d683fc452cb7b45569a5095f6a");
        //调用初始化对象里面的方法,传递request,获取数据
        response=client.getAcsResponse(request);
        List<GetPlayInfoResponse.PlayInfo> playInfoList = response.getPlayInfoList();
        //播放地址
        for (GetPlayInfoResponse.PlayInfo playInfo : playInfoList) {
            System.out.print("PlayInfo.PlayURL = " + playInfo.getPlayURL() + "\n");
        }
        //Base信息
        System.out.print("VideoBase.Title = " + response.getVideoBase().getTitle() + "\n");

    }
}

第二个

package com.atguigu.vodtest;

import com.aliyun.oss.ClientException;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.profile.DefaultProfile;

/**
 * @Description:
 * @Author: a寕
 * @Date:2021/8/3 18:54
 */
public class InitObject {
    public static DefaultAcsClient initVodClient(String accessKeyId, String accessKeySecret) throws ClientException {
        String regionId = "cn-shanghai";  // 点播服务接入区域
        DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
        DefaultAcsClient client = new DefaultAcsClient(profile);
        return client;
    }
}

## ``实现
![在这里插入图片描述](https://www.icode9.com/i/ll/?i=4b97980158fa47869c70895856fad70f.png?,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5MDk4MzU2,size_16,color_FFFFFF,t_70)


标签:vod,上传,request,传中,aliyun,import,com,response,视屏
来源: https://blog.csdn.net/qq_39098356/article/details/119381223