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
StudentDao.java 385B
TeacherDao.java 385B
LiveMaterialDao.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+
- 资源: 2571
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 使用C++实现的常见算法
- travel-web-springboot【程序员VIP专用】.zip
- 基于Matlab, ConvergeCase中部分2D结果文件输出至EXCEL中 能力有限,代码和功能极其简陋.zip
- java桌面小程序,主要为游戏.zip学习资源
- Java桌面-坦克大战小游戏.zip程序资源
- java语言做的魔板小游戏.zip
- 初学JAVA制作的坦克大战小游戏,使用JAVA 的GUI模拟2,5D界面.zip
- 公开整理-2024年832个国家级贫困县摘帽情况分省分年统计.xlsx
- 纯js+Jquery实现2048游戏
- 叠罗汉游戏,安卓java实现,自定义Framlayout,属性动画.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功