package cn.jerryshell.liveteaching.controller;
import cn.jerryshell.liveteaching.config.VideoConfig;
import cn.jerryshell.liveteaching.model.Course;
import cn.jerryshell.liveteaching.model.Video;
import cn.jerryshell.liveteaching.model.VideoMaterial;
import cn.jerryshell.liveteaching.service.CourseService;
import cn.jerryshell.liveteaching.service.TeacherService;
import cn.jerryshell.liveteaching.service.VideoMaterialService;
import cn.jerryshell.liveteaching.service.VideoService;
import cn.jerryshell.liveteaching.util.Util;
import cn.jerryshell.liveteaching.vm.VideoViewModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpSession;
import java.net.MalformedURLException;
import java.util.List;
import java.util.UUID;
@Controller
public class VideoController {
@Autowired
private VideoService videoService;
@Autowired
private VideoConfig videoConfig;
@Autowired
private CourseService courseService;
@Autowired
private TeacherService teacherService;
@Autowired
private VideoMaterialService videoMaterialService;
@GetMapping("/video")
public String toVideoListPage(Model model) {
return toVideoListPage(model, videoService.findAll());
}
@GetMapping("/video/course/{courseId}")
public String toVideoListByCourseIdPage(@PathVariable String courseId, Model model) {
return toVideoListPage(model, videoService.findByCourseId(courseId));
}
private String toVideoListPage(Model model, List<Video> videoList) {
List<Course> courseList = courseService.findAll();
model.addAttribute("courseList", courseList);
List<VideoViewModel> videoVMList = VideoViewModel.loadFromVideoList(
videoList,
teacherService,
courseService,
videoMaterialService
);
model.addAttribute("videoVMList", videoVMList);
return "video-list";
}
@PostMapping("/video/upload")
public String upload(
Video video,
@RequestParam("videoFile") MultipartFile videoFile,
@RequestParam("videoMaterial") MultipartFile videoMaterialFile,
HttpSession session
) {
String videoFilename = videoFile.getOriginalFilename();
if (StringUtils.isEmpty(videoFilename)) {
return "redirect:/user/upload-video";
}
// 视频后缀名
String videoFileType = Util.getFileTypeByFilename(videoFilename);
// 只能解码 mp4 文件
if (!"mp4".equals(videoFileType)) {
return "redirect:/user/upload-video";
}
video.setId(UUID.randomUUID().toString());
video.setTeacherId(session.getAttribute("loginUserId").toString());
video.setFileType(videoFileType);
videoService.uploadVideo(videoFile, video.getId() + "." + video.getFileType());
videoService.save(video);
// 视频资料
String materialFilename = videoMaterialFile.getOriginalFilename();
if (StringUtils.isEmpty(materialFilename)) {
return "redirect:/user/video-list";
}
VideoMaterial videoMaterial = new VideoMaterial();
videoMaterial.setId(UUID.randomUUID().toString());
videoMaterial.setVideoId(video.getId());
videoMaterial.setFileType(Util.getFileTypeByFilename(materialFilename));
videoMaterialService.upload(videoMaterialFile, videoMaterial.getId() + "." + videoMaterial.getFileType());
videoMaterialService.save(videoMaterial);
return "redirect:/user/video-list";
}
@GetMapping("/video/{videoId}")
public String videoWatching(@PathVariable String videoId, Model model) {
Video video = videoService.findById(videoId);
if (video == null) {
return "redirect:/video";
}
VideoMaterial videoMaterial = videoMaterialService.findByVideoId(videoId);
model.addAttribute("videoId", videoId);
model.addAttribute("videoName", video.getId() + "." + video.getFileType());
model.addAttribute("videoMaterial", videoMaterial);
return "video-watching";
}
@DeleteMapping("/video/{videoId}")
public String deleteVideo(@PathVariable String videoId) {
videoService.deleteVideoById(videoId);
VideoMaterial videoMaterial = videoMaterialService.findByVideoId(videoId);
if (videoMaterial != null) {
videoMaterialService.deleteById(videoMaterial.getId());
}
return "redirect:/user/video-list";
}
@GetMapping("/video/download/{filename}")
public ResponseEntity<Resource> download(@PathVariable String filename) throws MalformedURLException {
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + filename + "\"")
.body(new UrlResource("file://" + videoConfig.getFilepath() + "/" + filename));
}
@GetMapping("/video/material/{materialId}")
public ResponseEntity<Resource> downloadMaterial(@PathVariable String materialId) throws MalformedURLException {
VideoMaterial videoMaterial = videoMaterialService.findById(materialId);
String filename = videoMaterial.getId() + "." + videoMaterial.getFileType();
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + filename + "\"")
.body(new UrlResource("file://" + videoConfig.getMaterialFilePath() + "/" + filename));
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
基于Java开发的在线直播平台源码(期末大作业).zip 已获高分通过的期末大作业项目源码,毕业设计、期末大作业、课程设计、高分必看,下载下来,简单部署,就可以使用。 基于Java开发的在线直播平台源码(期末大作业).zip 已获高分通过的期末大作业项目源码,毕业设计、期末大作业、课程设计、高分必看,下载下来,简单部署,就可以使用。基于Java开发的在线直播平台源码(期末大作业).zip 已获高分通过的期末大作业项目源码,毕业设计、期末大作业、课程设计、高分必看,下载下来,简单部署,就可以使用。基于Java开发的在线直播平台源码(期末大作业).zip 已获高分通过的期末大作业项目源码,毕业设计、期末大作业、课程设计、高分必看,下载下来,简单部署,就可以使用。基于Java开发的在线直播平台源码(期末大作业).zip 已获高分通过的期末大作业项目源码,毕业设计、期末大作业、课程设计、高分必看,下载下来,简单部署,就可以使用。基于Java开发的在线直播平台源码(期末大作业).zip 已获高分通过的期末大作业项目源码,毕业设计、期末大作业、课程设计、高分必看,下载下来,简单部署,就可以使用
资源推荐
资源详情
资源评论
收起资源包目录
基于Java开发的在线直播平台源码(期末大作业).zip (137个子文件)
mvnw.cmd 6KB
nginx.live.conf 2KB
srs.http.hls.conf 605B
bootstrap.min.css 152KB
DPlayer.min.css 51KB
video-js.min.css 38KB
chatMain.css 5KB
video.css 2KB
user-right.css 2KB
loginStyle.css 1KB
style.css 996B
user-left.css 957B
demo.css 743B
zhibo.css 716B
watching.css 117B
.gitignore 303B
teachers.html 6KB
user-teacher-create-live.html 4KB
main.html 4KB
user-teacher-upload-video.html 4KB
user-teacher.html 4KB
register-student.html 3KB
user-teacher-video-list.html 3KB
user-student.html 3KB
register-teacher.html 3KB
login.html 2KB
user-student-homework-list.html 2KB
video-list.html 2KB
live-watching.html 2KB
header.html 2KB
user-teacher-sidebar.html 2KB
homework-list.html 2KB
chat.html 2KB
live-list.html 2KB
video-watching.html 1KB
user-student-sidebar.html 1KB
maven-wrapper.jar 47KB
VideoController.java 6KB
UserController.java 5KB
HomeworkController.java 5KB
LiveViewModel.java 5KB
MavenWrapperDownloader.java 5KB
LiveController.java 4KB
VideoViewModel.java 3KB
HomeworkViewModel.java 3KB
LoginController.java 3KB
Live.java 2KB
RegisterController.java 2KB
LiveCountInterceptor.java 2KB
HomeworkService.java 2KB
Video.java 2KB
Homework.java 2KB
VideoService.java 2KB
VideoMaterialService.java 2KB
Student.java 2KB
LiveMaterialService.java 2KB
ChatController.java 2KB
MvcConfig.java 1KB
LiveDaoTest.java 1KB
TeacherDaoTest.java 1KB
Teacher.java 1KB
StudentService.java 1KB
TeacherService.java 1KB
LiveService.java 1012B
Carousel.java 970B
LiveMaterial.java 960B
WebSocketConfig.java 840B
MainController.java 788B
LiveConfig.java 786B
VideoMaterial.java 727B
LiveTeachingApplication.java 713B
LoginInterceptor.java 703B
Course.java 682B
Major.java 680B
VideoConfig.java 675B
ChatMessage.java 667B
LiveDao.java 647B
CourseService.java 555B
MajorService.java 534B
HomeworkDao.java 530B
HomeworkConfig.java 442B
SecurityConfig.java 435B
VideoDao.java 405B
VideoMaterialDao.java 391B
TeacherDao.java 385B
LiveMaterialDao.java 385B
StudentDao.java 385B
LiveTeachingApplicationTests.java 358B
CarouselDao.java 289B
CourseDao.java 283B
MajorDao.java 280B
Util.java 224B
t7.jpg 240KB
t3.jpg 152KB
bg1.jpg 150KB
t6.jpg 150KB
t4.jpg 117KB
teacher.jpg 116KB
bg2.jpg 115KB
bg3.jpg 114KB
共 137 条
- 1
- 2
资源评论
- weixin_608411372023-12-25感谢资源主分享的资源解决了我当下的问题,非常有用的资源。
- 懒懒蓝2023-12-14发现一个宝藏资源,赶紧冲冲冲!支持大佬~
- my6812024-06-03内容与描述一致,超赞的资源,值得借鉴的内容很多,支持!
猰貐的新时代
- 粉丝: 1w+
- 资源: 2886
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 光纤到户及通信基础设施报装申请表.docx
- 踝关节功能丧失程度评定表.docx
- 环保设施投资估算表.docx
- 既有建筑物通信报装申请表.docx
- 既有建筑物通信报装现场查勘报告.docx
- 监督机构检查记录表.docx
- 肩关节功能丧失程度评定表.docx
- 大学生创新创业训练计划大创项目的全流程指南
- 简易低风险工业厂房通信报装申请表.docx
- 建设工程消防验收各阶段意见回复表.docx
- 建设工程消防验收模拟验收意见表.docx
- 建设工程消防验收图纸核查意见表.docx
- 建设工程消防验收现场指导意见表.docx
- 建筑工程竣工验收消防设计质量检查报告(表格填写模板).docx
- 建筑工程消防查验意见和结论.docx
- 建筑工程消防施工竣工报告(表格填写模板).docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功