本地视频播放测试
This commit is contained in:
parent
0988f1dae8
commit
04c1cfb2a9
@ -0,0 +1,23 @@
|
|||||||
|
package cn.skcks.docking.gb28181.wvp.advice;
|
||||||
|
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 全局异常处理类
|
||||||
|
*
|
||||||
|
* @author Shikong
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@ControllerAdvice
|
||||||
|
public class BasicExceptionAdvice {
|
||||||
|
@ExceptionHandler(Exception.class)
|
||||||
|
public void exception(HttpServletRequest request, Exception e) {
|
||||||
|
if(request.getRequestURI().equals("/video")){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package cn.skcks.docking.gb28181.wvp.api;
|
||||||
|
|
||||||
|
import cn.skcks.docking.gb28181.wvp.config.SwaggerConfig;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import org.springdoc.core.models.GroupedOpenApi;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.core.io.FileSystemResource;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
@Tag(name = "视频api")
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("/video")
|
||||||
|
public class VideoController {
|
||||||
|
@Bean
|
||||||
|
public GroupedOpenApi videoApi() {
|
||||||
|
return SwaggerConfig.api("VideoApi", "/video");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "获取视频")
|
||||||
|
@GetMapping(consumes = MediaType.APPLICATION_OCTET_STREAM_VALUE, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
|
||||||
|
public ResponseEntity<FileSystemResource> video(HttpServletResponse response) {
|
||||||
|
response.reset();
|
||||||
|
// response.setHeader("Content-Type","video/mp4");
|
||||||
|
File f = new File("E:\\#Camera\\DCIM\\100MEDIA\\20230818\\NORM0003.MP4");
|
||||||
|
// try (
|
||||||
|
// BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(f));
|
||||||
|
// BufferedOutputStream outputStream = new BufferedOutputStream(response.getOutputStream())) {
|
||||||
|
// IoUtil.copy(inputStream, outputStream);
|
||||||
|
// }
|
||||||
|
|
||||||
|
FileSystemResource fileSystemResource = new FileSystemResource(f);
|
||||||
|
return ResponseEntity.ok().body(fileSystemResource);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user