Name is required.
Email address is required.
Invalid email address
Answer is required.
Exceeding max length of 5KB

Invalid header range coming from jwplayer used in android webview


I am using, jwplayer in android webview and when I play videos from player I can see invalid range is coming, so for in valid range I am using following code to server videos in jersey,

StreamingOutput output = new StreamingOutput() {
@Override
public void write(OutputStream output) throws IOException,
WebApplicationException {
@SuppressWarnings("resource")
final FileChannel inputChannel = new FileInputStream(file).getChannel();
final WritableByteChannel outputChannel = Channels.newChannel(output);
try {
inputChannel.transferTo(0, inputChannel.size(), outputChannel);
} finally {
// closing the channels
inputChannel.close();
outputChannel.close();
}
}
};
MimetypesFileTypeMap typeMap = new MimetypesFileTypeMap();
String mt = typeMap.getContentType(file);
if(fileName.contains(".mp4")) {
mt = "video/mp4";
}
return Response.ok(output, mt).header(HttpHeaders.CONTENT_LENGTH, file.length()).build();


And for valid range, I am using following code to serve videos . . . .

final int chunk_size = 1024 * 1024; // 1MB chunks
String[] ranges = range.split("=")[1].split("-");
final int from = Integer.parseInt(ranges[0]);
/**
* Chunk media if the range upper bound is unspecified. Chrome sends "bytes=0-"
*/
int to = chunk_size + from;
if (to >= file.length()) {
to = (int) (file.length() - 1);
}
if (ranges.length == 2) {
to = Integer.parseInt(ranges[1]);
}

final String responseRange = String.format("bytes %d-%d/%d", from, to, file.length());
final RandomAccessFile raf = new RandomAccessFile(file, "r");
raf.seek(from);

final int len = to - from + 1;
final MediaStreamer streamer = new MediaStreamer(len, raf);
MimetypesFileTypeMap typeMap = new MimetypesFileTypeMap();
String mt = typeMap.getContentType(file);
if(fileName.contains(".mp4")) {
mt = "video/mp4";
}
Response.ResponseBuilder res = Response.ok(streamer, mt).status(206)
.header("Accept-Ranges", "bytes")
.header("Content-Range", responseRange)
.header(HttpHeaders.CONTENT_LENGTH, streamer.getLenth())
.header(HttpHeaders.LAST_MODIFIED, new Date(file.lastModified()));
return res.build();



But still I am not able to run videos from android webview, on ios and desktop browsers all videos work fine.
What should I do here . . . . I don't think thats a encoding issue . . . .

6 Community Answers

dsmartpillars

User  
0 rated :

Also video is taken from my android nexus 5 . . . .

Cooper Reid

JW Player Support Agent  
0 rated :

We do not support embedding our JavaScript web player within a native app using web-view. Web view doesn’t have the type of video support that true browsers do.
-Cooper

dsmartpillars

User  
0 rated :

But same also not working on regular android chrome browser. Do you want url from me to check??

dsmartpillars

User  
0 rated :

If you want I can email you link of our page, you can check same on android chrome browser.

dsmartpillars

User  
0 rated :

did you guys get whats happening on my page??

Cooper Reid

JW Player Support Agent  
0 rated :

It sounds like there may be an issue with the way your server is serving your video content. I have never heard of this issue -
Cooper

This question has received the maximum number of answers.