0

How can i start from some position or jump to some position(bytes or seconds) and don't forget that i'm streaming mp3 file from server?

    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();
    }
}

Server implementation:

     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);

     }
user1610362
  • 637
  • 2
  • 9
  • 26
  • Your question is too ample. In what aspect are you confused about? – E_net4 Sep 14 '12 at 11:27
  • If user wants to play from 20s then i should probably send some string message to server saying him to start streaming from 20s is there any way to do it? I suppose that there is some class suitable for this and my server implementation is very simple 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); } – user1610362 Sep 14 '12 at 11:33
  • Then you should describe your server application in the question. For a moment I thought you wanted that to work for any MP3 file in any server. – E_net4 Sep 14 '12 at 11:36

0 Answers0