Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

重大BUG。视频seek在最后,再往回seek到中间,数据出错,播放器无法播放。 #23

Open
yoakerin opened this issue Feb 23, 2023 · 1 comment

Comments

@yoakerin
Copy link

分析后发现问题出在这里。
类 Mp4Response.java
方法 public void sendBody(Socket socket, OutputStream outputStream, long pending) throws Exception{

}
如下代码
while (bufferLength > 0 && (readLength = randomAccessFile.read(buffer, 0, (int) bufferLength)) != -1) {
offset += readLength;
outputStream.write(buffer, 0, readLength);
randomAccessFile.seek(offset);
bufferLength = (avilable - offset + 1) > bufferedSize ? bufferedSize : (avilable - offset + 1);
}
这里判断条件有问题。当第一次seek到结尾的时候,缓存文件中前面段没写入的数据,此段数据为空数据,再次往回seek,此时read 后,readLength 长度不是-1,但向buffer数组中写入的全是0,播放器接受到的全是空数据,也跳不出while循环。

@bozaixing
Copy link

分析后发现问题出在这里。
类 Mp4Response.java
方法 public void sendBody(Socket socket, OutputStream outputStream, long pending) throws Exception{

}
如下代码
while (bufferLength > 0 && (readLength = randomAccessFile.read(buffer, 0, (int) bufferLength)) != -1) {
offset += readLength;
outputStream.write(buffer, 0, readLength);
randomAccessFile.seek(offset);
bufferLength = (avilable - offset + 1) > bufferedSize ? bufferedSize : (avilable - offset + 1);
}
这里判断条件有问题。当第一次seek到结尾的时候,缓存文件中前面段没写入的数据,此段数据为空数据,再次往回seek,此时read 后,readLength 长度不是-1,但向buffer数组中写入的全是0,播放器接受到的全是空数据,也跳不出while循环。

大佬,这个问题最后怎么解决的呢?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants