Skip to content

Commit 582225c

Browse files
authored
Merge pull request saravanastar#2 from emawind84/master
bug fix
2 parents f8d8d99 + a120d9d commit 582225c

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/main/java/com/ask/home/videostream/service/VideoStreamService.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,18 @@ public ResponseEntity<byte[]> prepareContent(String fileName, String fileType, S
4242
if (range == null) {
4343
return ResponseEntity.status(HttpStatus.OK)
4444
.header(CONTENT_TYPE, VIDEO_CONTENT + fileType)
45-
.header(CONTENT_LENGTH, String.valueOf(fileSize - 1))
46-
.body(readByteRange(fullFileName, rangeStart, fileSize)); // Read the object and convert it as bytes
45+
.header(CONTENT_LENGTH, String.valueOf(fileSize))
46+
.body(readByteRange(fullFileName, rangeStart, fileSize - 1)); // Read the object and convert it as bytes
4747
}
4848
String[] ranges = range.split("-");
4949
rangeStart = Long.parseLong(ranges[0].substring(6));
5050
if (ranges.length > 1) {
5151
rangeEnd = Long.parseLong(ranges[1]);
5252
} else {
53-
rangeEnd = fileSize;
53+
rangeEnd = fileSize - 1;
5454
}
5555
if (fileSize < rangeEnd) {
56-
rangeEnd = fileSize;
56+
rangeEnd = fileSize - 1;
5757
}
5858
data = readByteRange(fullFileName, rangeStart, rangeEnd);
5959
} catch (IOException e) {
@@ -65,7 +65,7 @@ public ResponseEntity<byte[]> prepareContent(String fileName, String fileType, S
6565
.header(CONTENT_TYPE, VIDEO_CONTENT + fileType)
6666
.header(ACCEPT_RANGES, BYTES)
6767
.header(CONTENT_LENGTH, contentLength)
68-
.header(CONTENT_RANGE, BYTES + " " + rangeStart + "-" + (rangeEnd - 1) + "/" + fileSize)
68+
.header(CONTENT_RANGE, BYTES + " " + rangeStart + "-" + rangeEnd + "/" + fileSize)
6969
.body(data);
7070

7171

@@ -90,8 +90,8 @@ public byte[] readByteRange(String filename, long start, long end) throws IOExce
9090
bufferedOutputStream.write(data, 0, nRead);
9191
}
9292
bufferedOutputStream.flush();
93-
byte[] result = new byte[(int) (end - start)];
94-
System.arraycopy(bufferedOutputStream.toByteArray(), (int) start, result, 0, (int) (end - start));
93+
byte[] result = new byte[(int) (end - start) + 1];
94+
System.arraycopy(bufferedOutputStream.toByteArray(), (int) start, result, 0, result.length);
9595
return result;
9696
}
9797
}

0 commit comments

Comments
 (0)