我试图部分地流MP3文件,但所有的要求“字节标志”前字节STIL下载:如何部分流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()); }
如何流部分?