【发布时间】:2015-06-19 21:43:05
【问题描述】:
我正在尝试部分流式传输 mp3 文件,但仍在下载请求的“字节标记”之前的所有字节:
- 假设 mp3 文件的文件大小为 7000000 字节。
- 我“跳转”到 6000000 字节并开始从那里流式传输到最后。
- 但我注意到,从 6000000 字节标记开始播放 mp3 文件之前,1-5999999 的每个字节都已下载。
-
我正在使用 JLayer (Java Zoom - http://www.javazoom.net/javalayer/javalayer.html) 播放 mp3 文件。
import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import javazoom.jl.decoder.JavaLayerException; import javazoom.jl.player.advanced.AdvancedPlayer; try { URL url = new URL("http://somerandomsite.com/audiotestfile.mp3"); URLConnection connection = url.openConnection(); connection.connect(); int fileSize = connection.getContentLength(); InputStream inputStream = url.openStream(); System.out.println("Filesize in bytes: " + fileSize); // Lets assume the filesize of the mp3 file is 7000000 bytes long skippedBytes = inputStream.skip(6000000); // Skip to 6000000 bytes to only stream the file partially System.out.println("Skipped bytes: " + skippedBytes); // The skipped bytes are equal to 6000000 bytes, but all previous bytes are still being downloaded. AdvancedPlayer ap = new AdvancedPlayer(inputStream); ap.play(); } catch (FileNotFoundException | JavaLayerException e) { System.out.println(e.getMessage()); }
如何进行部分流式传输?
【问题讨论】: