我遇到了一个使用springMVC StreamingResponseBody返回视频的问题.我从服务器上获得的视频被打断了.你们能给我一个暗示吗?
视频文件被分块了
我的控制器:
@RestController
@RequestMapping("/rest/videos")
public class VideoController {
private String videoLocation = "videos";
private ConcurrentHashMap<String, File> videos = new ConcurrentHashMap<String, File>();
@PostConstruct
public void init() {
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
File dir = new File(classloader.getResource(videoLocation).getPath());
System.out.println(dir);
videos.clear();
videos.putAll(Arrays.asList(dir.listFiles()).stream()
.collect(Collectors.toMap((f) -> {
String name = ((File) f).getName();
return name;
}, (f) -> (File) f)));
}
@RequestMapping(method = RequestMethod.GET, value = "/{video:.+}")
@PreAuthorize("permitAll")
public StreamingResponseBody stream(@PathVariable String video)
throws FileNotFoundException {
File videoFile = videos.get(video);
final InputStream videoFileStream = new …Run Code Online (Sandbox Code Playgroud)