我試圖部分地流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()); }
如何流部分?