質問編集履歴

1

プログラム修正し、リクエスト・レスポンス情報を追加

2017/09/05 06:55

投稿

Begi
Begi

スコア56

test CHANGED
File without changes
test CHANGED
@@ -213,3 +213,223 @@
213
213
  VideoAction.javaのResult又はStreamの指定に問題があるのではと思っています。
214
214
 
215
215
  情報に不足などありましたらご指摘ください。よろしくお願いします。
216
+
217
+
218
+
219
+
220
+
221
+ ###追記
222
+
223
+ othersight様、A-pZ様
224
+
225
+ 時間が空いてしまい申し訳ありません。
226
+
227
+ https://www.stevesouders.com/blog/2013/04/21/html5-video-bytes-on-ios/
228
+
229
+ 等を参考に、レスポンスヘッダにAccept-Range、Content-Rangeを仕込み、Content-LengthはリクエストヘッダのRangeが0-1だった場合は2を返すなど行いましたが、未だ解決に至っていません。
230
+
231
+ ソースは以下になります。
232
+
233
+ ```VideoAction.java
234
+
235
+ HttpServletRequest request = getRequest(); //リクエストヘッダを取得
236
+
237
+ String range = request.getHeader("Range").replace("bytes=", "");
238
+
239
+ String rangeFirst = range.substring(0, range.indexOf("-"));
240
+
241
+ String rangeLast = range.substring(range.indexOf("-") + 1, range.length());
242
+
243
+ String contentRange = "";
244
+
245
+
246
+
247
+ HttpServletResponse response = getResponse();
248
+
249
+ response.setStatus(206);
250
+
251
+ response.setHeader("Accept-Ranges", "bytes");
252
+
253
+
254
+
255
+ //range: "0-"
256
+
257
+ if (range.equals("0-")) {
258
+
259
+ contentRange = "bytes " + rangeFirst + "-" + (Integer.parseInt(rangeFirst) + 1) + "/" + this.contentLength;
260
+
261
+ }
262
+
263
+ //range: "0-x"
264
+
265
+ if (range.indexOf("0-") != -1 && (!rangeLast.isEmpty() && !rangeLast.equals("0"))) {
266
+
267
+ contentRange = "bytes " + rangeFirst + "-" + rangeLast + "/" + this.contentLength;
268
+
269
+ }
270
+
271
+ //range: "x-"
272
+
273
+ if (!rangeFirst.equals("0") && range.lastIndexOf("-") != -1) {
274
+
275
+ contentRange = "bytes " + rangeFirst + "-" + String.valueOf(this.contentLength - 1) + "/" + this.contentLength;
276
+
277
+ }
278
+
279
+ //range: "0-1"
280
+
281
+ if (range.equals("0-1")) {
282
+
283
+ contentRange = "bytes 0-1/" + this.contentLength;
284
+
285
+ this.contentLength = 2;
286
+
287
+ }
288
+
289
+ //range: "x-x"
290
+
291
+ if (!rangeFirst.equals("0") && range.lastIndexOf("-") == -1) {
292
+
293
+ contentRange = "bytes " + rangeFirst + "-" + (Integer.parseInt(rangeLast) + 1) + "/" + this.contentLength;
294
+
295
+ this.contentLength = 2;
296
+
297
+ }
298
+
299
+
300
+
301
+ response.setHeader("Content-Range", contentRange);
302
+
303
+ System.out.println("★レスポンスRange--- " + contentRange);
304
+
305
+ System.out.println("★コンテントLength--- " + this.contentLength);
306
+
307
+
308
+
309
+ ```
310
+
311
+
312
+
313
+ 上記のソースを仕込み、1回目のリクエストに対しては正常に動作しましたが2回目のリクエストからはサーバ側で
314
+
315
+ 重大: Exception occurred during processing request: java.io.IOException: 確立された接続がホスト コンピューターのソウトウェアによって中止されました。 [月 8 28 16:19:18 JST 2017]
316
+
317
+ がまた発生してしまいます。
318
+
319
+ Last-ModifiedやEtagなど仕込むことも試しましたが、変わらないようです。
320
+
321
+ 以下リクエスト、レスポンスになります。
322
+
323
+ ```
324
+
325
+ 1回目のリクエスト
326
+
327
+ Accept:*/*
328
+
329
+ Accept-Encoding:identity;q=1, *;q=0
330
+
331
+ Accept-Language:ja,en-US;q=0.8,en;q=0.6
332
+
333
+ Cache-Control:no-cache
334
+
335
+ Connection:keep-alive
336
+
337
+ Cookie:JSESSIONID=0D946AEE3ABF37850218436884DEB391; _ga=GA1.1.2024693826.1504524761; _gid=GA1.1.353248483.1504524761
338
+
339
+ Host:localhost:8080
340
+
341
+ Pragma:no-cache
342
+
343
+ Range:bytes=0-
344
+
345
+ Referer:http://localhost:8080/test/test.action
346
+
347
+ User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36
348
+
349
+ ```
350
+
351
+ ```
352
+
353
+ 1回目のレスポンス
354
+
355
+ Accept-Ranges:bytes
356
+
357
+ Connection:Keep-Alive
358
+
359
+ Content-Disposition:attachment; filename =
360
+
361
+ Content-Language:ja
362
+
363
+ Content-Length:1595162
364
+
365
+ Content-Range:bytes 0-1/1595162
366
+
367
+ Content-Type:video/mp4
368
+
369
+ Date:Tue, 05 Sep 2017 06:35:37 GMT
370
+
371
+ Etag:42b795-4867d5fcac1c0
372
+
373
+ Server:Apache-Coyote/1.1
374
+
375
+ ```
376
+
377
+ ```
378
+
379
+ 2回目のリクエスト
380
+
381
+ Accept:*/*
382
+
383
+ Accept-Encoding:identity;q=1, *;q=0
384
+
385
+ Accept-Language:ja,en-US;q=0.8,en;q=0.6
386
+
387
+ Cache-Control:no-cache
388
+
389
+ Connection:keep-alive
390
+
391
+ Cookie:JSESSIONID=0D946AEE3ABF37850218436884DEB391; _ga=GA1.1.2024693826.1504524761; _gid=GA1.1.353248483.1504524761
392
+
393
+ Host:localhost:8080
394
+
395
+ Pragma:no-cache
396
+
397
+ Range:bytes=1572864-
398
+
399
+ Referer:http://localhost:8080/test/test.action
400
+
401
+ User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36
402
+
403
+ ```
404
+
405
+ ```
406
+
407
+ 2回目のレスポンス
408
+
409
+ Accept-Ranges:bytes
410
+
411
+ Connection:Keep-Alive
412
+
413
+ Content-Disposition:attachment; filename =
414
+
415
+ Content-Language:ja
416
+
417
+ Content-Length:1595162
418
+
419
+ Content-Range:bytes 1572864-1595161/1595162
420
+
421
+ Content-Type:video/mp4
422
+
423
+ Date:Tue, 05 Sep 2017 06:35:37 GMT
424
+
425
+ Etag:42b795-4867d5fcac1c0
426
+
427
+ Server:Apache-Coyote/1.1
428
+
429
+ ```
430
+
431
+
432
+
433
+ すみませんが、何かわかることがありましたらご教授いただけますでしょうか。
434
+
435
+ よろしくお願いいたします。