0

我如何从某个位置开始或跳转到某个位置(字节或秒)并且不要忘记我正在从服务器流式传输 mp3 文件?

    static private void rawplay(AudioFormat targetFormat, AudioInputStream din)
        throws Exception {
    byte[] data = new byte[4096];
    SourceDataLine line = getLine(targetFormat);

    if (line != null) {
        // Start
        line.start();
        int nBytesRead = 0, nBytesWritten = 0;


    while (nBytesRead != -1) {
            nBytesRead = din.read(data, 0, data.length);
            if (nBytesRead != -1){
                if(someFloat==-3)nBytesWritten = line.write(data, 10, nBytesRead);
                else nBytesWritten = line.write(data, 0, nBytesRead);
            }

        }
        // Stop
        line.drain();
        line.stop();
        line.close();
        din.close();
    }
}

服务器实现:

     out = new DataOutputStream(sock.getOutputStream());
     File file = new File("src/f.mp3"); 
     DataInputStream inFile = new DataInputStream(new FileInputStream(file));
     long length=0;
     byte[] buffer = new byte[1024];
     while((length=inFile.read(buffer,0,1024))>0){
         out.write(buffer,0,(int)length);

     }
4

0 回答 0