All pastes #676692 Raw Edit

Mine

public text v1 · immutable
#676692 ·published 2007-08-31 09:55 UTC
rendered paste body
Server side:

    public void transfer(DataOutputStream output) {
         try{  
      
 
            
       
                   int i = 0;
                   int auglis = 50058; //chunk size
                   
                   
                   
              
                //if it is wav file, we need to edit header:
                
                   //audio[4] = (byte)0x8A;
                   //     audio[5] = (byte)0xC3;
                  //  audio[6] = (byte)0x00;
                  //  audio[7] = (byte)0x00;
                  
                   //  audio[54] = (byte)0x50;
                  //  audio[55] = (byte)0xC3;
                  // audio[56] = (byte)0x00;
                  // audio[57] = (byte)0x00;
                  
                  
                   byte[] tmp = new byte[50058];
                   int countBytes= 0;
                   int headerup = 32; //mp3 header is 32 bytes.
                   
                while(i<50058){
                 tmp[i] = audio[i]; //byte array audio is byte array from mp3 file
                 i++;
                 countBytes++;
                   }  
                output.writeInt(50058);     //write to midlet, that chunk size will be 50058
                output.write(tmp);   //write chunk itself
                     
                   boolean varam = true; //booleand that will become false, when file ends
                   while(varam){
                 
                   int tmplen = garums - countBytes; //check if it is not last chunk
   
                   int o=50058;
                   if(tmplen>50058){ //if it is not last chunk
                     o = 50058;  
                   }
                   else{
                   o = tmplen+headerup; // if it is last chunk
                   tmp = new byte[o];
                   varam = false; //out while loop will end
                   }
                   
                       int z = 0;
                       while(z<32){ //write 32 byte header to chunk
                       tmp[z] = audio[z];          
                       z++;
                       countBytes++;
                       }   
                             
                       while(z<o){ //white chunk it self
                       tmp[z] = audio[i];
                       z++;
                       i++;
                       countBytes++;
                       }  
                          
                  headerup =  headerup +32;
                  output.writeInt(o);          //white size of chunk (typically 50058)
                  output.write(tmp);    //white chunk itself
              
                   }
         
         
         }
         catch (Exception e) {}
    }




Midlet:

   Thread tt = new Thread(){
               
                 byte[] tmp = new byte[50058]; //byte array for 1st player
                 byte[] tmpdata = new byte[50058]; //byte array for second player
                 Player player=null;
                 Player player2 = null;
                 ByteArrayInputStream ain;
                 ByteArrayInputStream ain2;
                 boolean jap = true; //jap will show become false, if last chunk will be reveived
          
              
                public synchronized void ieladejam(){ //ieladejam is loading (in Latvian)
                    try{
                        if(jap){
                      int i = 0;
                      int o = in.readInt(); //read chunk size
                      if(o!=50058){
                          tmp = new byte[o]; //if this is last chunk, then chunk size will be similar as remaining bytes
                          jap = false;
                      }
                      int z = 0;
                       while(i><o){
                          if(in.available()==0){ //this is for my nokia 6260 and some other nokia wich have blutooth bugs, this should be removed
                                  Thread.sleep(30);
                          }
                          if(z==500){
                                  Thread.sleep(30); //this also is for 6260 bluetooth bug, this should be removed
                                  z=0;
                          }
                       z++;
                      tmp[i] = (byte)in.read(); 
                      i++;      
                         }
                      
                  ain = new ByteArrayInputStream(tmp); //make Byteinputstream from data chunk
                  player = Manager.createPlayer(ain, "audio/mpeg"); //initialize player with this data chunk
                  player.realize();
                  player.prefetch();
                        }
                    }
                     catch(Exception e){e.printStackTrace();}
                }
                
                    public synchronized void ieladejam2(){ //the same as ieladejam, but for player 2
                    try{
                    if(jap){    
                      int i = 0;
                      int o = in.readInt();
                        if(o!=50058){
                          tmpdata = new byte[o];
                          jap = false;
         
                      }   
                      int z = 0;
                       while(i><o){
                          if(in.available()==0){
                                  Thread.sleep(30);
                          }
                          if(z==500){
                                  Thread.sleep(30);
                                  z=0;
                          }
                       z++;
                      tmpdata[i] = (byte)in.read();
                      i++;      
                         }
                  ain2 = new ByteArrayInputStream(tmpdata);
                  player2 = Manager.createPlayer(ain2, "audio/mpeg");
                  player2.realize();
                  player2.prefetch();
                    }
                    }
                     catch(Exception e){e.printStackTrace();}
                }
                
              public synchronized void play(){    
         
              
               try{
                  if(jap){                               
                  player.start();    //start playing                      
                  ieladejam2(); //while playing start loading next chunk
                  while(player.getState() == Player.STARTED){ //while plaing don`t start to play next chunk
                  }
                  play2(); //if player has finished playing, thad we can start playing next chunk
                  }
                  else{
                      
                       player.start();   
                      
                      
                  }
                  }
                  catch(Exception e){e.printStackTrace();}
              }
               
               public synchronized void play2(){ //same ar play(), but for player2    
               try{
                   if(jap){
                  player2.start();
                  ieladejam();
                  while(player2.getState() == Player.STARTED){
                  }
                  play();
                   }
                   else{
                    player2.start(); 
           
                
                   
                   
                       
                   }
                  }
                  catch(Exception e){e.printStackTrace();}
              }
               
         
               
               public void run(){  
               ieladejam();
               buff.append("Now playing.."); //append some form with text
               play();
           }
           };
           tt.start();

>