视频播放参数修改
This commit is contained in:
		@@ -2,6 +2,7 @@ package com.stdiet.web.controller.custom;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
import com.aliyun.vod20170321.models.CreateUploadVideoResponse;
 | 
			
		||||
import com.aliyun.vod20170321.models.GetVideoListResponseBody;
 | 
			
		||||
@@ -37,28 +38,11 @@ public class SysNutritionalVideoController extends BaseController
 | 
			
		||||
    public AjaxResult list(SysNutritionalVideo sysNutritionalVideo, @RequestParam(value = "pageNum", defaultValue = "1") int pageNum, @RequestParam(value = "pageSize", defaultValue = "5")int pageSize)
 | 
			
		||||
    {
 | 
			
		||||
        AjaxResult result = AjaxResult.success();
 | 
			
		||||
        int total = 0;
 | 
			
		||||
        List<SysNutritionalVideo> nutritionalVideoList = new ArrayList<>();
 | 
			
		||||
        try{
 | 
			
		||||
            GetVideoListResponseBody videoListResponseBody = AliyunVideoUtils.getVideoListByPage(null, "Normal,Blocked", pageNum, pageSize);
 | 
			
		||||
            if(videoListResponseBody != null){
 | 
			
		||||
                total = videoListResponseBody.total;
 | 
			
		||||
                for (GetVideoListResponseBody.GetVideoListResponseBodyVideoListVideo video : videoListResponseBody.videoList.video) {
 | 
			
		||||
                    SysNutritionalVideo nutritionalVideo = new SysNutritionalVideo();
 | 
			
		||||
                    nutritionalVideo.setCoverUrl(video.getCoverURL());
 | 
			
		||||
                    nutritionalVideo.setTitle(video.getTitle());
 | 
			
		||||
                    nutritionalVideo.setVideoId(video.getVideoId());
 | 
			
		||||
                    nutritionalVideo.setDescription(video.getDescription());
 | 
			
		||||
                    nutritionalVideo.setTags(video.getTags());
 | 
			
		||||
                    nutritionalVideoList.add(nutritionalVideo);
 | 
			
		||||
                    nutritionalVideo.setShowFlag("Normal".equals(video.getStatus()) ? 1 : 0);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }catch (Exception e){
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        Map<String, Object> map = sysNutritionalVideoService.searchVideo(sysNutritionalVideo.getKey(), sysNutritionalVideo.getShowFlag(), pageNum, pageSize, null);
 | 
			
		||||
        if(map != null){
 | 
			
		||||
            result.put("total", map.get("total"));
 | 
			
		||||
            result.put("rows", map.get("nutritionalVideoList"));
 | 
			
		||||
        }
 | 
			
		||||
        result.put("total",total);
 | 
			
		||||
        result.put("rows", nutritionalVideoList);
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -368,27 +368,9 @@ public class WechatAppletController extends BaseController {
 | 
			
		||||
    @GetMapping(value = "/getVideoList")
 | 
			
		||||
    public AjaxResult getVideoList(SysNutritionalVideo sysNutritionalVideo, @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,  @RequestParam(value = "pageSize", defaultValue = "5")int pageSize) {
 | 
			
		||||
        AjaxResult result = AjaxResult.success();
 | 
			
		||||
        int total = 0;
 | 
			
		||||
        List<NutritionalVideoResponse> nutritionalVideoList = new ArrayList<>();
 | 
			
		||||
        try{
 | 
			
		||||
            GetVideoListResponseBody videoListResponseBody = AliyunVideoUtils.getVideoListByPage(null, "Normal", pageNum, pageSize);
 | 
			
		||||
            if(videoListResponseBody != null){
 | 
			
		||||
                total = videoListResponseBody.total;
 | 
			
		||||
                for (GetVideoListResponseBody.GetVideoListResponseBodyVideoListVideo video : videoListResponseBody.videoList.video) {
 | 
			
		||||
                    NutritionalVideoResponse nutritionalVideoResponse = new NutritionalVideoResponse();
 | 
			
		||||
                    nutritionalVideoResponse.setCoverUrl(video.getCoverURL());
 | 
			
		||||
                    nutritionalVideoResponse.setTitle(video.getTitle());
 | 
			
		||||
                    nutritionalVideoResponse.setVideoId(video.getVideoId());
 | 
			
		||||
                    nutritionalVideoResponse.setDescription(video.getDescription());
 | 
			
		||||
                    nutritionalVideoResponse.setTags(video.getTags());
 | 
			
		||||
                    nutritionalVideoList.add(nutritionalVideoResponse);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }catch (Exception e){
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
        result.put("total",total);
 | 
			
		||||
        result.put("rows", nutritionalVideoList);
 | 
			
		||||
        Map<String, Object> map = sysNutritionalVideoService.searchVideo(sysNutritionalVideo.getKey(), 1, pageNum, pageSize, null);
 | 
			
		||||
        result.put("total", map.get("total"));
 | 
			
		||||
        result.put("rows", map.get("nutritionalVideoList"));
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -14,11 +14,13 @@ public class AliyunVideoUtils {
 | 
			
		||||
 | 
			
		||||
    public static final String default_output_type = "oss";
 | 
			
		||||
 | 
			
		||||
    public static final String default_formats = "mp4";
 | 
			
		||||
    public static final String default_formats = "cdn";
 | 
			
		||||
 | 
			
		||||
    //播放地址日期,30天
 | 
			
		||||
    public static final Long default_authTimeout = 2592000L;
 | 
			
		||||
 | 
			
		||||
    public static final String search_field = "VideoId,Title,CoverURL,CateName,Tags,Status,Description,CreationTime";
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 初始化视频点播Client
 | 
			
		||||
     * @return
 | 
			
		||||
@@ -43,7 +45,7 @@ public class AliyunVideoUtils {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 分页获取视频列表
 | 
			
		||||
     * 分页获取视频列表(限于5000条,不能关键词搜索)
 | 
			
		||||
     * @param pageNo 页码
 | 
			
		||||
     * @param pageSize 每页数量
 | 
			
		||||
     * @return
 | 
			
		||||
@@ -120,6 +122,36 @@ public class AliyunVideoUtils {
 | 
			
		||||
        return client.createUploadVideo(createUploadVideoRequest);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     *
 | 
			
		||||
     * @param key
 | 
			
		||||
     * @param status
 | 
			
		||||
     * @param pageNo
 | 
			
		||||
     * @param pageSize
 | 
			
		||||
     * @throws Exception
 | 
			
		||||
     */
 | 
			
		||||
    public static SearchMediaResponse searchVideo(String key, String status, Integer pageNo, Integer pageSize, String scrollToken) throws Exception{
 | 
			
		||||
        com.aliyun.vod20170321.Client client = AliyunVideoUtils.createClient();
 | 
			
		||||
        SearchMediaRequest searchMediaRequest = new SearchMediaRequest()
 | 
			
		||||
                .setSearchType("video")
 | 
			
		||||
                .setFields(search_field)
 | 
			
		||||
                .setPageNo(pageNo == null ? 1 : pageNo)
 | 
			
		||||
                .setPageSize(pageSize == null ? 10 : pageSize)
 | 
			
		||||
                .setScrollToken(scrollToken);
 | 
			
		||||
        if(StringUtils.isNotEmpty(key) || StringUtils.isNotEmpty(status)){
 | 
			
		||||
            String matchString = null;
 | 
			
		||||
            if(StringUtils.isNotEmpty(key)){
 | 
			
		||||
                matchString += StringUtils.format("(Title = '%s' or  Description = '%s')", key, key);
 | 
			
		||||
            }
 | 
			
		||||
            if(StringUtils.isNotEmpty(status)) {
 | 
			
		||||
                matchString += matchString == null ? "" : " and ";
 | 
			
		||||
                matchString += StringUtils.format("(Status = '%s')", status);
 | 
			
		||||
            }
 | 
			
		||||
            System.out.println(matchString);
 | 
			
		||||
            searchMediaRequest.setMatch(matchString);
 | 
			
		||||
        }
 | 
			
		||||
        return client.searchMedia(searchMediaRequest);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -55,4 +55,6 @@ public class SysNutritionalVideo extends BaseEntity
 | 
			
		||||
 | 
			
		||||
    //文件名称
 | 
			
		||||
    private String fileName;
 | 
			
		||||
 | 
			
		||||
    private String key;
 | 
			
		||||
}
 | 
			
		||||
@@ -1,6 +1,8 @@
 | 
			
		||||
package com.stdiet.custom.service;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
import com.stdiet.custom.domain.SysNutritionalVideo;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@@ -65,4 +67,10 @@ public interface ISysNutritionalVideoService
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    public SysNutritionalVideo selectSysNutritionalVideByVideoId(String videoId);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 阿里云视频查询检索
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    public Map<String,Object> searchVideo(String key, Integer status, Integer pageNo, Integer pageSize, String scrollToken);
 | 
			
		||||
}
 | 
			
		||||
@@ -1,6 +1,13 @@
 | 
			
		||||
package com.stdiet.custom.service.impl;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
import com.aliyun.vod20170321.models.SearchMediaResponse;
 | 
			
		||||
import com.aliyun.vod20170321.models.SearchMediaResponseBody;
 | 
			
		||||
import com.stdiet.common.utils.AliyunVideoUtils;
 | 
			
		||||
import com.stdiet.common.utils.DateUtils;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
@@ -102,4 +109,60 @@ public class SysNutritionalVideoServiceImpl implements ISysNutritionalVideoServi
 | 
			
		||||
    public SysNutritionalVideo selectSysNutritionalVideByVideoId(String videoId){
 | 
			
		||||
        return sysNutritionalVideoMapper.selectSysNutritionalVideByVideoId(videoId);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 阿里云视频查询检索
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    public Map<String,Object> searchVideo(String key, Integer showFlag, Integer pageNo, Integer pageSize, String scrollToken){
 | 
			
		||||
        pageSize = pageSize.intValue() > 100 ? 10 : pageSize;
 | 
			
		||||
        long total = 0;
 | 
			
		||||
        String newScrollToken = null;
 | 
			
		||||
        List<SysNutritionalVideo> nutritionalVideoList = new ArrayList<>();
 | 
			
		||||
        try {
 | 
			
		||||
            SearchMediaResponse response = AliyunVideoUtils.searchVideo(key, getStatusString(showFlag), pageNo, pageSize, scrollToken);
 | 
			
		||||
            if(response != null){
 | 
			
		||||
                SearchMediaResponseBody body  = response.body;
 | 
			
		||||
                total = body.total;
 | 
			
		||||
                newScrollToken = body.scrollToken;
 | 
			
		||||
                List<SearchMediaResponseBody.SearchMediaResponseBodyMediaList> mediaList = body.mediaList;
 | 
			
		||||
                if(mediaList != null && mediaList.size() > 0){
 | 
			
		||||
                    for (SearchMediaResponseBody.SearchMediaResponseBodyMediaList media : mediaList) {
 | 
			
		||||
                        SysNutritionalVideo sysNutritionalVideo = new SysNutritionalVideo();
 | 
			
		||||
                        sysNutritionalVideo.setTitle(media.video.title);
 | 
			
		||||
                        sysNutritionalVideo.setCoverUrl(media.video.coverURL);
 | 
			
		||||
                        sysNutritionalVideo.setShowFlag(getStatus(media.video.getStatus()));
 | 
			
		||||
                        sysNutritionalVideo.setTags(media.video.tags);
 | 
			
		||||
                        String createTime = media.video.creationTime;
 | 
			
		||||
                        System.out.println(createTime);
 | 
			
		||||
                        sysNutritionalVideo.setDescription(media.video.description);
 | 
			
		||||
                        sysNutritionalVideo.setVideoId(media.video.videoId);
 | 
			
		||||
                        nutritionalVideoList.add(sysNutritionalVideo);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }catch (Exception e){
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
        Map<String, Object> result = new HashMap<>();
 | 
			
		||||
        result.put("total", total);
 | 
			
		||||
        result.put("newScrollToken", newScrollToken);
 | 
			
		||||
        result.put("nutritionalVideoList", nutritionalVideoList);
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private String getStatusString(Integer status){
 | 
			
		||||
        if(status == null){
 | 
			
		||||
            return "Normal,Blocked";
 | 
			
		||||
        }
 | 
			
		||||
        return status.intValue() == 1 ? "Normal" : "Blocked";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private Integer getStatus(String status){
 | 
			
		||||
        if(status == null){
 | 
			
		||||
            return 1;
 | 
			
		||||
        }
 | 
			
		||||
        return "Normal".equals(status) ? 1 :  0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user