视频播放接口
This commit is contained in:
		| @@ -1,31 +1,104 @@ | ||||
| package com.stdiet.web.controller.custom; | ||||
|  | ||||
| import com.aliyun.vod20170321.models.GetPlayInfoResponseBody; | ||||
| import com.stdiet.common.core.controller.BaseController; | ||||
| import com.stdiet.common.core.domain.AjaxResult; | ||||
| import com.stdiet.common.core.page.TableDataInfo; | ||||
| import com.stdiet.common.utils.AliyunVideoUtils; | ||||
| import com.stdiet.common.utils.StringUtils; | ||||
| import com.stdiet.common.utils.oss.AliyunOSSUtils; | ||||
| import com.stdiet.custom.domain.SysNutritionalVideo; | ||||
| import com.stdiet.custom.domain.SysVideoClassify; | ||||
| import com.stdiet.custom.dto.response.NutritionalVideoResponse; | ||||
| import com.stdiet.custom.dto.response.VideoClassifyResponse; | ||||
| import com.stdiet.custom.service.ISysNutritionalVideoService; | ||||
| import com.stdiet.custom.service.ISysVideoClassifyService; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.web.bind.annotation.GetMapping; | ||||
| import org.springframework.web.bind.annotation.RequestMapping; | ||||
| import org.springframework.web.bind.annotation.RestController; | ||||
| import org.springframework.web.bind.annotation.*; | ||||
|  | ||||
| import java.util.List; | ||||
|  | ||||
|  | ||||
| @RestController | ||||
| @RequestMapping("/web/video") | ||||
| public class VideoWebInterfaceController { | ||||
| public class VideoWebInterfaceController extends BaseController { | ||||
|  | ||||
|     @Autowired | ||||
|     private ISysVideoClassifyService sysVideoClassifyService; | ||||
|  | ||||
|     @Autowired | ||||
|     private ISysNutritionalVideoService sysNutritionalVideoService; | ||||
|  | ||||
|     /** | ||||
|      * 查询视频分类目录列表 | ||||
|      */ | ||||
|     @GetMapping("/getAllClassify") | ||||
|     public AjaxResult getClassifyAndVideo(SysVideoClassify sysVideoClassify) | ||||
|     public TableDataInfo getClassifyAndVideo(SysVideoClassify sysVideoClassify) | ||||
|     { | ||||
|         List<SysVideoClassify> list = sysVideoClassifyService.getAllClassifyAndVideo(0L); | ||||
|         return AjaxResult.success(list); | ||||
|         //不分页则不需要传pageNum、pageSize参数 | ||||
|         startPage(); | ||||
|         //父级分类ID 0表示主分类 | ||||
|         sysVideoClassify.setParentId(0L); | ||||
|         //客户类型 0 未付费客户  1已付费客户 | ||||
|         sysVideoClassify.setUserType(1); | ||||
|         List<VideoClassifyResponse> list = sysVideoClassifyService.getAllClassifyAndVideo(sysVideoClassify); | ||||
|         return getDataTable(list); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * 根据视频videoId获取视频详情以及播放地址 | ||||
|      * @param videoId 阿里云中对应videoId | ||||
|      * @return | ||||
|      */ | ||||
|     @GetMapping("/getVideoDetail/{videoId}") | ||||
|     public AjaxResult getVideoDetail(@PathVariable("videoId") String videoId) | ||||
|     { | ||||
|         if(StringUtils.isEmpty(videoId)){ | ||||
|             return AjaxResult.error("视频加载失败"); | ||||
|         } | ||||
|         SysNutritionalVideo sysNutritionalVideo = sysNutritionalVideoService.selectSysNutritionalVideByVideoId(videoId); | ||||
|         if(sysNutritionalVideo == null){ | ||||
|             return AjaxResult.error("视频加载失败"); | ||||
|         } | ||||
|         NutritionalVideoResponse nutritionalVideoResponse = new NutritionalVideoResponse(); | ||||
|         try { | ||||
|             GetPlayInfoResponseBody playInfoResponseBody = AliyunVideoUtils.getVideoVisitDetail(videoId); | ||||
|             List<GetPlayInfoResponseBody.GetPlayInfoResponseBodyPlayInfoListPlayInfo> playList = playInfoResponseBody.playInfoList.playInfo; | ||||
|             if (playList != null && playList.size() > 0) { | ||||
|                 //播放地址 | ||||
|                 nutritionalVideoResponse.setPlayUrl(playList.get(0).getPlayURL()); | ||||
|             } | ||||
|         }catch (Exception e){ | ||||
|             e.printStackTrace(); | ||||
|             return AjaxResult.error("视频加载失败"); | ||||
|         } | ||||
|         //视频封面URL | ||||
|         if (StringUtils.isNotEmpty(sysNutritionalVideo.getCoverUrl())) { | ||||
|             nutritionalVideoResponse.setCoverUrl(AliyunOSSUtils.generatePresignedUrl(sysNutritionalVideo.getCoverUrl())); | ||||
|         } else { | ||||
|             nutritionalVideoResponse.setCoverUrl(AliyunVideoUtils.getVideoCoverUrl(videoId)); | ||||
|         } | ||||
|         //视频描述 | ||||
|         nutritionalVideoResponse.setDescription(sysNutritionalVideo.getDescription()); | ||||
|         //视频标题 | ||||
|         nutritionalVideoResponse.setTitle(sysNutritionalVideo.getTitle()); | ||||
|         //视频播放量 | ||||
|         nutritionalVideoResponse.setPlayNum(sysNutritionalVideo.getPlayNum()); | ||||
|  | ||||
|         return AjaxResult.success(nutritionalVideoResponse); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 更新视频播放次数 | ||||
|      * @param videoId 阿里云中对应videoId | ||||
|      * @return | ||||
|      */ | ||||
|     @GetMapping(value = "/updateVideoPlayNum") | ||||
|     public AjaxResult updateVideoPlayNum(@RequestParam(value = "videoId") String videoId) { | ||||
|         if(StringUtils.isEmpty(videoId)){ | ||||
|             return AjaxResult.error("更新失败"); | ||||
|         } | ||||
|         return toAjax(sysNutritionalVideoService.updateVideoPlayNum(videoId)); | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user