Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
2892 connectés 

  FORUM HardWare.fr
  Programmation
  Java

  Besoin d'aide java

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Besoin d'aide java

n°2144696
julesm74
noobi
Posté le 06-06-2012 à 00:20:55  profilanswer
 

Bonsoir
Je ne suis pas sur d'être dans le bon forum sinon dites le moi et supprimée se poste.
 
Alors Voila j'ai crée une application java enfin plutôt modifier un launcher pour un serveur de jeux (minecraft)
Et j'ai une petit idée serai t'il possible de mettre une petite musique de fond pendant que les joueurs marque leur login mot de passe?
Et donc si ses possible savez vous quel portion de code que je dois ajouté dans le code du launcher pour qu'une musique démarre au lancement du launcher.
Si vous voulez je peut fournir le code source si vous en avez besoin
 
Merci pour vos futur réponse
 
Cordialement julesm74

mood
Publicité
Posté le 06-06-2012 à 00:20:55  profilanswer
 

n°2144722
willy le k​id
Posté le 06-06-2012 à 10:31:34  profilanswer
 

Si c'est en java, il n'y a pas de difficulté technique . . . tu peux googler "java play mp3 game background"
 
Si c'est en API minecraft . . . tu te trompes de forum

n°2144731
julesm74
noobi
Posté le 06-06-2012 à 11:08:48  profilanswer
 

Non ce n'est pas en api minecraft.
Mais le problème ce que je débute vraiment en java.
Et ou je peut trouvé le code exacte à incorporé dans ma classe principale?

n°2144743
Terminapor
I'll see you rise.
Posté le 06-06-2012 à 11:25:32  profilanswer
 

MC possède un lecteur de musique (format ogg je crois), certes il est utilisé une fois à chaque alignement de toutes les planètes, mais tu peux commencer par zieuter ça :o


---------------
Perhaps you don't deserve to breathe
n°2144746
julesm74
noobi
Posté le 06-06-2012 à 11:30:04  profilanswer
 

La je parle du launcher pas du jeux.
Donc pas de musique de base.
 
/*    */ package net.minecraft;
/*    */
/*     */ import java.applet.Applet;
/*     */ import java.io.BufferedReader;
/*     */ import java.io.BufferedWriter;
/*     */ import java.io.DataInputStream;
/*     */ import java.io.DataOutputStream;
/*     */ import java.io.File;
/*     */ import java.io.FileInputStream;
/*     */ import java.io.FileOutputStream;
/*     */ import java.io.FilePermission;
/*     */ import java.io.FileWriter;
/*     */ import java.io.IOException;
/*     */ import java.io.InputStream;
/*     */ import java.io.InputStreamReader;
/*     */ import java.io.OutputStream;
/*     */ import java.io.PrintStream;
/*     */ import java.io.PrintWriter;
/*     */ import java.io.StringWriter;
/*     */ import java.io.Writer;
/*     */ import java.lang.reflect.Constructor;
/*     */ import java.lang.reflect.Field;
/*     */ import java.lang.reflect.Method;
/*     */ import java.net.HttpURLConnection;
/*     */ import java.net.JarURLConnection;
/*     */ import java.net.SocketPermission;
/*     */ import java.net.URI;
/*     */ import java.net.URL;
/*     */ import java.net.URLClassLoader;
/*     */ import java.net.URLConnection;
/*     */ import java.security.AccessControlException;
/*     */ import java.security.AccessController;
/*     */ import java.security.CodeSource;
/*     */ import java.security.PermissionCollection;
/*     */ import java.security.PrivilegedExceptionAction;
/*     */ import java.security.ProtectionDomain;
/*     */ import java.security.SecureClassLoader;
/*     */ import java.security.cert.Certificate;
/*     */ import java.util.Enumeration;
/*     */ import java.util.Scanner;
/*     */ import java.util.StringTokenizer;
/*     */ import java.util.Vector;
/*     */ import java.util.jar.JarEntry;
/*     */ import java.util.jar.JarFile;
/*     */ import java.util.jar.JarOutputStream;
/*     */ import java.util.jar.Pack200;
import java.util.jar.Pack200.Unpacker;
/*    */
/*    */ public class GameUpdater
/*    */  implements Runnable
/*    */ {
/*    */  public static final int STATE_INIT = 1;
/*    */  public static final int STATE_DETERMINING_PACKAGES = 2;
/*    */  public static final int STATE_CHECKING_CACHE = 3;
/*    */  public static final int STATE_DOWNLOADING = 4;
/*    */  public static final int STATE_EXTRACTING_PACKAGES = 5;
/*    */  public static final int STATE_UPDATING_CLASSPATH = 6;
/*    */  public static final int STATE_SWITCHING_APPLET = 7;
/*    */  public static final int STATE_INITIALIZE_REAL_APPLET = 8;
/*    */  public static final int STATE_START_REAL_APPLET = 9;
/*    */  public static final int STATE_DONE = 10;
/*    */  public int percentage;
/*    */  public int currentSizeDownload;
/*    */  public int totalSizeDownload;
public static boolean forceUpdate = false;
/*    */  public int currentSizeExtract;
/*    */  public int totalSizeExtract;
/*    */  protected URL[] urlList;
/*    */  private static ClassLoader classLoader;
/*    */  protected Thread loaderThread;
/*    */  protected Thread animationThread;
/*    */  public boolean fatalError;
          public boolean pauseAskUpdate;
          public boolean shouldUpdate;
/*    */  public String fatalErrorDescription;
/*  80 */  protected String subtaskMessage = "";
/*  81 */  protected int state = 1;
/*    */
/*  83 */  protected boolean lzmaSupported = false;
/*  84 */  protected boolean pack200Supported = false;
/*    */
/*  86 */  protected String[] genericErrorMessage = { "An error occured while loading the applet.", "Please contact support to resolve this issue.", "<placeholder for error message>" };
/*    */  protected boolean certificateRefused;
/*  90 */  protected String[] certificateRefusedMessage = { "Permissions for Applet Refused.", "Please accept the permissions dialog to allow", "the applet to continue the loading process." };
/*    */
/*  92 */  protected static boolean natives_loaded = false;
/*    */  private String latestVersion;
/*    */  private String mainGameUrl;
/*    */
/*    */  public GameUpdater(String latestVersion, String mainGameUrl)
/*    */  {
/*  97 */    this.latestVersion = latestVersion;
/*  98 */    this.mainGameUrl = mainGameUrl;
/*    */  }
/*    */
/*    */  public void init() {
/* 102 */    this.state = 1;
/*    */    try
/*    */    {
/* 105 */      Class.forName("LZMA.LzmaInputStream" );
/* 106 */      this.lzmaSupported = true;
/*    */    }
/*    */    catch (Throwable localThrowable) {
/*    */    }
/*    */    try {
/* 111 */      Pack200.class.getSimpleName();
/* 112 */      this.pack200Supported = true;
/*    */    } catch (Throwable localThrowable1) {
/*    */    }
/*    */  }
/*    */
/*    */  private String generateStacktrace(Exception exception) {
/* 118 */    Writer result = new StringWriter();
/* 119 */    PrintWriter printWriter = new PrintWriter(result);
/* 120 */    exception.printStackTrace(printWriter);
/* 121 */    return result.toString();
/*    */  }
/*    */
/*    */  protected String getDescriptionForState()
/*    */  {
/* 129 */    switch (this.state) {
/*    */    case 1:
/* 131 */      return "Initialisation du téléchargement";
/*    */    case 2:
/* 133 */      return "Détérmination des packs à télécharger";
/*    */    case 3:
/* 135 */      return "Vérifcation du cache pour les fichiers éxistants";
/*    */    case 4:
/* 137 */      return "Téléchargement des packs";
/*    */    case 5:
/* 139 */      return "Extraction des packs";
/*    */    case 6:
/* 141 */      return "Mise à jour du classpath";
/*    */    case 7:
/* 143 */      return "Changement d'applet";
/*    */    case 8:
/* 145 */      return "Initialisation de l'applet";
/*    */    case 9:
/* 147 */      return "Démarrage de l'applet";
/*    */    case 10:
/* 149 */      return "Chargement terminé";
/*     */   case 11:
               return "Mise à  jour Horyzon";
/*    */    }
/* 151 */    return "Phase inconnu";
/*    */  }
 
 
 
 
 
 
/*    */
/*    */  protected String trimExtensionByCapabilities(String file)
/*    */  {
/* 156 */    if (!this.pack200Supported) {
/* 157 */      file = file.replaceAll(".pack", "" );
/*    */    }
/*    */
/* 160 */    if (!this.lzmaSupported) {
/* 161 */      file = file.replaceAll(".lzma", "" );
/*    */    }
/* 163 */    return file;
/*    */  }
/*    */
/*     */   protected void loadJarURLs() throws Exception {
   /* 165 */     this.state = 2;
   /* 166 */     String jarList = "lwjgl.jar, jinput.jar, lwjgl_util.jar, " + this.mainGameUrl;
   /* 167 */     jarList = trimExtensionByCapabilities(jarList);
   /*     */  
   /* 169 */     StringTokenizer jar = new StringTokenizer(jarList, ", " );
   /* 170 */     int jarCount = jar.countTokens() + 1;
   /*     */  
   /* 172 */     this.urlList = new URL[jarCount];
   /*     */  
   /* 174 */     URL path = new URL("http://s3.amazonaws.com/MinecraftDownload/" );
   /*     */  
   /* 176 */     for (int i = 0; i < jarCount - 1; i++) {
   /* 177 */       String nextToken = jar.nextToken();
   /* 178 */       URL oldPath = path;
   /*     */  
   /* 181 */       if (nextToken.indexOf("craft.jar" ) >= 0) {
   /* 182 */         path = new URL("http://www.Horyzon.eu/launcher/minecraft.jar" );
   /*     */       }
   /*     */  
   /* 185 */       System.out.println(path + nextToken.replaceAll("minecraft.jar", "minecraft.jar" ));
   /* 186 */       if (nextToken.indexOf("craft.jar" ) >= 0) {
   /* 187 */         this.urlList[i] = new URL(path, nextToken.replaceAll("minecraft.jar", "minecraft.jar" ));
   /*     */       }
   /*     */       else {
   /* 190 */         this.urlList[i] = new URL(path, nextToken);
   /*     */       }
   /*     */  
   /* 194 */       if (nextToken.indexOf("craft.jar" ) >= 0) {
   /* 195 */         path = oldPath;
   /*     */       }
   /*     */     }
   /*     */  
   /* 199 */     String osName = System.getProperty("os.name" );
   /* 200 */     String nativeJar = null;
   /*     */  
   /* 202 */     if (osName.startsWith("Win" ))
   /* 203 */       nativeJar = "windows_natives.jar.lzma";
   /* 204 */     else if (osName.startsWith("Linux" ))
   /* 205 */       nativeJar = "linux_natives.jar.lzma";
   /* 206 */     else if (osName.startsWith("Mac" ))
   /* 207 */       nativeJar = "macosx_natives.jar.lzma";
   /* 208 */     else if ((osName.startsWith("Solaris" )) || (osName.startsWith("SunOS" )))
   /* 209 */       nativeJar = "solaris_natives.jar.lzma";
   /*     */     else {
   /* 211 */       fatalErrorOccured("OS (" + osName + " ) not supported", null);
   /*     */     }
   /*     */  
   /* 214 */     if (nativeJar == null) {
   /* 215 */       fatalErrorOccured("no lwjgl natives files found", null);
   /*     */     } else {
   /* 217 */       nativeJar = trimExtensionByCapabilities(nativeJar);
   /* 218 */       this.urlList[(jarCount - 1)] = new URL(path, nativeJar);
   /*     */     }
   /*     */   }
/*    */
/*     */   public void run()
/*     */   {
/* 224 */     init();
/* 225 */     this.state = 3;
/*     */  
/* 227 */     this.percentage = 5;
/*     */     try
/*     */     {
/* 230 */       loadJarURLs();
/*     */  
/* 232 */       String path = (String)AccessController.doPrivileged(new PrivilegedExceptionAction() {
/*     */         public Object run() throws Exception {
/* 234 */           return Util.getWorkingDirectory() + File.separator + "bin" + File.separator;
/*     */         }
/*     */       });
/* 237 */       File dir = new File(path);
/*     */  
/* 239 */       if (!dir.exists()) {
/* 240 */         dir.mkdirs();
/*     */       }
/*     */  
/* 243 */       if (this.latestVersion != null) {
/* 244 */         File versionFile = new File(dir, "version" );
 
 
/*     */  
/* 246 */         boolean cacheAvailable = false;
/* 247 */         if ((versionFile.exists()) && (
/* 248 */           (this.latestVersion.equals("-1" )) || (this.latestVersion.equals(readVersionFile(versionFile))))) {
/* 249 */           cacheAvailable = true;
/* 250 */           this.percentage = 90;
/*     */         }
/*     */  
/* 254 */         boolean updateHoryzon = false;
/*     */         try {
/* 256 */           String version_Horyzon = "";
/* 257 */           URL url_version = new URL("http://www.Horyzon.eu/launcher/horyzon.txt" );
/*     */           try {
/* 259 */             BufferedReader in = new BufferedReader(new InputStreamReader(url_version.openStream()));
/* 260 */             version_Horyzon = in.readLine();
/*     */           }
/*     */           catch (Exception e) {
/* 263 */             System.err.println(e);
/*     */           }
/* 265 */           File current_version_Horyzon = new File(dir, "Horyzon.txt" );
/*     */  
/* 267 */           if (!current_version_Horyzon.exists()) {
/* 268 */             updateHoryzon = true;
/*     */             try {
/* 270 */               BufferedWriter bw = new BufferedWriter(new FileWriter(current_version_Horyzon));
/* 271 */               bw.append(version_Horyzon);
/* 272 */               bw.close();
/*     */             } catch (IOException e) {
/* 274 */               System.out.println("Erreur" );
/*     */             }
/*     */           }
/*     */           else
/*     */           {
/*     */             try {
/* 280 */               Scanner scanner = new Scanner(current_version_Horyzon);
/* 281 */               while (scanner.hasNextLine()) {
/* 282 */                 String line = scanner.nextLine().trim();
/* 283 */                 if (!version_Horyzon.equals(line)) {
/* 284 */                   updateHoryzon = true;
/*     */                   try {
/* 286 */                     BufferedWriter bw = new BufferedWriter(new FileWriter(current_version_Horyzon));
/* 287 */                     bw.append(version_Horyzon);
/* 288 */                     bw.close();
/*     */                   } catch (IOException e) {
/* 290 */                     System.out.println("Erreur" );
/*     */                   }
/*     */                 }
/*     */               }
/*     */  
/* 295 */               scanner.close();
/*     */             } catch (IOException e) {
/* 297 */               System.out.println("Erreur" + e.getMessage());
/*     */             }
/*     */  
/*     */           }
/*     */  
/*     */         }
/*     */         catch (Exception localException1)
/*     */         {
/*     */         }
/*     */  
/* 308 */         if ((!cacheAvailable) || (updateHoryzon) || (forceUpdate))  {
/* 309 */           downloadJars(path);
/* 310 */           extractJars(path);
/* 311 */           extractNatives(path);
/*     */  
/* 313 */           if (this.latestVersion != null) {
/* 314 */             this.percentage = 90;
/* 315 */             writeVersionFile(versionFile, this.latestVersion);
/*     */           }
/*     */         }
/*     */       }
/*     */  
/* 320 */       updateClassPath(dir);
/* 321 */       this.state = 10;
/*     */     } catch (AccessControlException ace) {
/* 323 */       fatalErrorOccured(ace.getMessage(), ace);
/* 324 */       this.certificateRefused = true;
/*     */     } catch (Exception e) {
/* 326 */       fatalErrorOccured(e.getMessage(), e);
/*     */     } finally {
/* 328 */       this.loaderThread = null;
/*     */     }
/*     */   }
/*     */  
/*     */   protected String readVersionFile(File file) throws Exception {
/* 333 */     DataInputStream dis = new DataInputStream(new FileInputStream(file));
/* 334 */     String version = dis.readUTF();
/* 335 */     dis.close();
/* 336 */     return version;
/*     */   }
/*     */  
/*     */   protected void writeVersionFile(File file, String version) throws Exception {
/* 340 */     DataOutputStream dos = new DataOutputStream(new FileOutputStream(file));
/* 341 */     dos.writeUTF(version);
/* 342 */     dos.close();
/*     */   }
/*    */
/*    */  protected void updateClassPath(File dir)
/*    */    throws Exception
/*    */  {
/* 278 */    this.state = 6;
/*    */
/* 280 */    this.percentage = 95;
/*    */
/* 282 */    URL[] urls = new URL[this.urlList.length];
/* 283 */    for (int i = 0; i < this.urlList.length; i++) {
/* 284 */      urls[i] = new File(dir, getJarName(this.urlList[i])).toURI().toURL();
/*    */    }
/*    */
/* 287 */    if (classLoader == null) {
/* 288 */      classLoader = new URLClassLoader(urls) {
/*    */        protected PermissionCollection getPermissions(CodeSource codesource) {
/* 290 */          PermissionCollection perms = null;
/*    */          try
/*    */          {
/* 294 */            Method method = SecureClassLoader.class.getDeclaredMethod("getPermissions", new Class[] { CodeSource.class });
/* 295 */            method.setAccessible(true);
/* 296 */            perms = (PermissionCollection)method.invoke(getClass().getClassLoader(), new Object[] { codesource });
/*    */
/* 298 */            String host = "www.minecraft.net";
/*    */
/* 300 */            if ((host != null) && (host.length() > 0))
/*    */            {
/* 302 */              perms.add(new SocketPermission(host, "connect,accept" ));
/*    */            } else codesource.getLocation().getProtocol().equals("file" );
/*    */
/* 306 */            perms.add(new FilePermission("<<ALL FILES>>", "read" ));
/*    */          }
/*    */          catch (Exception e) {
/* 309 */            e.printStackTrace();
/*    */          }
/*    */
/* 312 */          return perms;
/*    */        }
/*    */      };
/*    */    }
/* 317 */    String path = dir.getAbsolutePath();
/* 318 */    if (!path.endsWith(File.separator)) path = path + File.separator;
/* 319 */    unloadNatives(path);
/*    */
/* 321 */    System.setProperty("org.lwjgl.librarypath", path + "natives" );
/* 322 */    System.setProperty("net.java.games.input.librarypath", path + "natives" );
/*    */
/* 324 */    natives_loaded = true;
/*    */  }
/*    */
/*    */  private void unloadNatives(String nativePath)
/*    */  {
/* 329 */    if (!natives_loaded) {
/* 330 */      return;
/*    */    }
/*    */    try
/*    */    {
/* 334 */      Field field = ClassLoader.class.getDeclaredField("loadedLibraryNames" );
/* 335 */      field.setAccessible(true);
/* 336 */      Vector libs = (Vector)field.get(getClass().getClassLoader());
/*    */
/* 338 */      String path = new File(nativePath).getCanonicalPath();
/*    */
/* 340 */      for (int i = 0; i < libs.size(); i++) {
/* 341 */        String s = (String)libs.get(i);
/*    */
/* 343 */        if (s.startsWith(path)) {
/* 344 */          libs.remove(i);
/* 345 */          i--;
/*    */        }
/*    */      }
/*    */    } catch (Exception e) {
/* 349 */      e.printStackTrace();
/*    */    }
/*    */  }
/*    */
/*    */  public Applet createApplet() throws ClassNotFoundException, InstantiationException, IllegalAccessException
/*    */  {
/* 355 */    Class appletClass = classLoader.loadClass("net.minecraft.client.MinecraftApplet" );
/* 356 */    return (Applet)appletClass.newInstance();
/*    */  }
/*    */
/*    */  protected void downloadJars(String path)
/*    */    throws Exception
/*    */  {
/* 384 */    this.state = 4;
/*    */
/* 389 */    int[] fileSizes = new int[this.urlList.length];
/*    */
/* 392 */    for (int i = 0; i < this.urlList.length; i++) {
/* 393 */      System.out.println(this.urlList[i]);
/* 394 */      URLConnection urlconnection = this.urlList[i].openConnection();
/* 395 */      urlconnection.setDefaultUseCaches(false);
/* 396 */      if ((urlconnection instanceof HttpURLConnection)) {
/* 397 */        ((HttpURLConnection)urlconnection).setRequestMethod("HEAD" );
/*    */      }
/* 399 */      fileSizes[i] = urlconnection.getContentLength();
/* 400 */      this.totalSizeDownload += fileSizes[i];
/*    */    }
/*    */
/* 403 */    int initialPercentage = this.percentage = 10;
/*    */
/* 406 */    byte[] buffer = new byte[65536];
/* 407 */    for (int i = 0; i < this.urlList.length; i++)
/*    */    {
/* 409 */      int unsuccessfulAttempts = 0;
/* 410 */      int maxUnsuccessfulAttempts = 3;
/* 411 */      boolean downloadFile = true;
/*    */
/* 414 */      while (downloadFile) {
/* 415 */        downloadFile = false;
/*    */
/* 417 */        URLConnection urlconnection = this.urlList[i].openConnection();
/*    */
/* 419 */        if ((urlconnection instanceof HttpURLConnection)) {
/* 420 */          urlconnection.setRequestProperty("Cache-Control", "no-cache" );
/* 421 */          urlconnection.connect();
/*    */        }
/*    */
/* 424 */        String currentFile = getFileName(this.urlList[i]);
/* 425 */        InputStream inputstream = getJarInputStream(currentFile, urlconnection);
/* 426 */        FileOutputStream fos = new FileOutputStream(path + currentFile);
/*    */
/* 430 */        long downloadStartTime = System.currentTimeMillis();
/* 431 */        int downloadedAmount = 0;
/* 432 */        int fileSize = 0;
/* 433 */        String downloadSpeedMessage = "";
/*    */        int bufferSize;
/* 435 */        while ((bufferSize = inputstream.read(buffer, 0, buffer.length)) != -1)
/*    */        {
/* 436 */          fos.write(buffer, 0, bufferSize);
/* 437 */          this.currentSizeDownload += bufferSize;
/* 438 */          fileSize += bufferSize;
/* 439 */          this.percentage = (initialPercentage + this.currentSizeDownload * 45 / this.totalSizeDownload);
/* 440 */          this.subtaskMessage = ("Téléchargement de " + currentFile + " " + this.currentSizeDownload * 100 / this.totalSizeDownload + "%" );
/*    */
/* 442 */          downloadedAmount += bufferSize;
/* 443 */          long timeLapse = System.currentTimeMillis() - downloadStartTime;
/*    */
/* 445 */          if (timeLapse >= 1000L)
/*    */          {
/* 447 */            float downloadSpeed = downloadedAmount / (float)timeLapse;
/*    */
/* 449 */            downloadSpeed = (int)(downloadSpeed * 100.0F) / 100.0F;
/*    */
/* 451 */            downloadSpeedMessage = " à " + downloadSpeed + " KB/sec";
/*    */
/* 453 */            downloadedAmount = 0;
/*    */
/* 455 */            downloadStartTime += 1000L;
/*    */          }
/*    */
/* 458 */          this.subtaskMessage += downloadSpeedMessage;
/*    */        }
/*    */
/* 461 */        inputstream.close();
/* 462 */        fos.close();
/*    */
/* 465 */        if ((!(urlconnection instanceof HttpURLConnection)) ||
/* 466 */          (fileSize == fileSizes[i]))
/*    */          continue;
/* 468 */        if (fileSizes[i] <= 0)
/*    */        {
/*    */          continue;
/*    */        }
/* 472 */        unsuccessfulAttempts++;
/*    */
/* 474 */        if (unsuccessfulAttempts < maxUnsuccessfulAttempts) {
/* 475 */          downloadFile = true;
/* 476 */          this.currentSizeDownload -= fileSize;
/*    */        }
/*    */        else {
/* 479 */          throw new Exception("Impossible de télécharger " + currentFile);
/*    */        }
/*    */      }
/*    */
/*    */    }
/*    */
/* 485 */    this.subtaskMessage = "";
/*    */  }
/*    */
/*    */  protected InputStream getJarInputStream(String currentFile, final URLConnection urlconnection)
/*    */    throws Exception
/*    */  {
/* 496 */    final InputStream[] is = new InputStream[1];
/*    */
/* 500 */    for (int j = 0; (j < 3) && (is[0] == null); j++) {
/* 501 */      Thread t = new Thread() {
/*    */        public void run() {
/*    */          try {
/* 504 */            is[0] = urlconnection.getInputStream();
/*    */          }
/*    */          catch (IOException localIOException)
/*    */          {
/*    */          }
/*    */        }
/*    */      };
/* 510 */      t.setName("JarInputStreamThread" );
/* 511 */      t.start();
/*    */
/* 513 */      int iterationCount = 0;
/* 514 */      while ((is[0] == null) && (iterationCount++ < 5)) {
/*    */        try {
/* 516 */          t.join(1000L);
/*    */        }
/*    */        catch (InterruptedException localInterruptedException)
/*    */        {
/*    */        }
/*    */      }
/* 522 */      if (is[0] != null) continue;
/*    */      try {
/* 524 */        t.interrupt();
/* 525 */        t.join();
/*    */      }
/*    */      catch (InterruptedException localInterruptedException1)
/*    */      {
/*    */      }
/*    */    }
/*    */
/* 532 */    if (is[0] == null) {
/* 533 */      if (currentFile.equals("minecraft.jar" )) {
/* 534 */        throw new Exception("Unable to download " + currentFile);
/*    */      }
/* 536 */      throw new Exception("Unable to download " + currentFile);
/*    */    }
/*    */
/* 541 */    return is[0];
/*    */  }
/*    */
/*    */  protected void extractLZMA(String in, String out)
/*    */    throws Exception
/*    */  {
/* 553 */    File f = new File(in);
/* 554 */    FileInputStream fileInputHandle = new FileInputStream(f);
/*    */
/* 557 */    Class clazz = Class.forName("LZMA.LzmaInputStream" );
/* 558 */    Constructor constructor = clazz.getDeclaredConstructor(new Class[] { InputStream.class });
/* 559 */    InputStream inputHandle = (InputStream)constructor.newInstance(new Object[] { fileInputHandle });
/*    */
/* 562 */    OutputStream outputHandle = new FileOutputStream(out);
/*    */
/* 564 */    byte[] buffer = new byte[16384];
/*    */
/* 566 */    int ret = inputHandle.read(buffer);
/* 567 */    while (ret >= 1) {
/* 568 */      outputHandle.write(buffer, 0, ret);
/* 569 */      ret = inputHandle.read(buffer);
/*    */    }
/*    */
/* 572 */    inputHandle.close();
/* 573 */    outputHandle.close();
/*    */
/* 575 */    outputHandle = null;
/* 576 */    inputHandle = null;
/*    */
/* 579 */    f.delete();
/*    */  }
/*    */
/*    */  protected void extractPack(String in, String out)
/*    */    throws Exception
/*    */  {
/* 590 */    File f = new File(in);
/* 591 */    FileOutputStream fostream = new FileOutputStream(out);
/* 592 */    JarOutputStream jostream = new JarOutputStream(fostream);
/*    */
/* 594 */    Pack200.Unpacker unpacker = Pack200.newUnpacker();
/* 595 */    unpacker.unpack(f, jostream);
/* 596 */    jostream.close();
/*    */
/* 599 */    f.delete();
/*    */  }
/*    */
/*    */  protected void extractJars(String path)
/*    */    throws Exception
/*    */  {
/* 609 */    this.state = 5;
/*    */
/* 611 */    float increment = 10.0F / this.urlList.length;
/*    */
/* 613 */    for (int i = 0; i < this.urlList.length; i++) {
/* 614 */      this.percentage = (55 + (int)(increment * (i + 1)));
/* 615 */      String filename = getFileName(this.urlList[i]);
/*    */
/* 617 */      if (filename.endsWith(".pack.lzma" )) {
/* 618 */        this.subtaskMessage = ("Extracting: " + filename + " to " + filename.replaceAll(".lzma", "" ));
/* 619 */        extractLZMA(path + filename, path + filename.replaceAll(".lzma", "" ));
/*    */
/* 621 */        this.subtaskMessage = ("Extracting: " + filename.replaceAll(".lzma", "" ) + " to " + filename.replaceAll(".pack.lzma", "" ));
/* 622 */        extractPack(path + filename.replaceAll(".lzma", "" ), path + filename.replaceAll(".pack.lzma", "" ));
/* 623 */      } else if (filename.endsWith(".pack" )) {
/* 624 */        this.subtaskMessage = ("Extracting: " + filename + " to " + filename.replace(".pack", "" ));
/* 625 */        extractPack(path + filename, path + filename.replace(".pack", "" ));
/* 626 */      } else if (filename.endsWith(".lzma" )) {
/* 627 */        this.subtaskMessage = ("Extracting: " + filename + " to " + filename.replace(".lzma", "" ));
/* 628 */        extractLZMA(path + filename, path + filename.replace(".lzma", "" ));
/*    */      }
/*    */    }
/*    */  }
/*    */
/*    */  protected void extractNatives(String path) throws Exception
/*    */  {
/* 635 */    this.state = 5;
/*    */
/* 637 */    int initialPercentage = this.percentage;
/*    */
/* 639 */    String nativeJar = getJarName(this.urlList[(this.urlList.length - 1)]);
/*    */
/* 641 */    Certificate[] certificate = Launcher.class.getProtectionDomain().getCodeSource().getCertificates();
/*    */
/* 643 */    if (certificate == null) {
/* 644 */      URL location = Launcher.class.getProtectionDomain().getCodeSource().getLocation();
/*    */
/* 646 */      JarURLConnection jurl = (JarURLConnection)new URL("jar:" + location.toString() + "!/net/minecraft/Launcher.class" ).openConnection();
/* 647 */      jurl.setDefaultUseCaches(true);
/*    */      try {
/* 649 */        certificate = jurl.getCertificates();
/*    */      }
/*    */      catch (Exception localException)
/*    */      {
/*    */      }
/*    */    }
/* 655 */    File nativeFolder = new File(path + "natives" );
/* 656 */    if (!nativeFolder.exists()) {
/* 657 */      nativeFolder.mkdir();
/*    */    }
/*    */
/* 660 */    JarFile jarFile = new JarFile(path + nativeJar, true);
/* 661 */    Enumeration entities = jarFile.entries();
/*    */
/* 663 */    this.totalSizeExtract = 0;
/*    */
/* 666 */    while (entities.hasMoreElements()) {
/* 667 */      JarEntry entry = (JarEntry)entities.nextElement();
/*    */
/* 671 */      if ((entry.isDirectory()) || (entry.getName().indexOf('/') != -1)) {
/*    */        continue;
/*    */      }
/* 674 */      this.totalSizeExtract = (int)(this.totalSizeExtract + entry.getSize());
/*    */    }
/*    */
/* 677 */    this.currentSizeExtract = 0;
/*    */
/* 679 */    entities = jarFile.entries();
/*    */
/* 681 */    while (entities.hasMoreElements()) {
/* 682 */      JarEntry entry = (JarEntry)entities.nextElement();
/*    */
/* 684 */      if ((entry.isDirectory()) || (entry.getName().indexOf('/') != -1))
/*    */      {
/*    */        continue;
/*    */      }
/* 688 */      File f = new File(path + "natives" + File.separator + entry.getName());
/* 689 */      if ((f.exists()) &&
/* 690 */        (!f.delete()))
/*    */      {
/*    */        continue;
/*    */      }
/*    */
/* 695 */      InputStream in = jarFile.getInputStream(jarFile.getEntry(entry.getName()));
/* 696 */      OutputStream out = new FileOutputStream(path + "natives" + File.separator + entry.getName());
/*    */
/* 699 */      byte[] buffer = new byte[65536];
/*    */      int bufferSize;
/* 701 */      while ((bufferSize = in.read(buffer, 0, buffer.length)) != -1)
/*    */      {
/* 702 */        out.write(buffer, 0, bufferSize);
/* 703 */        this.currentSizeExtract += bufferSize;
/*    */
/* 705 */        this.percentage = (initialPercentage + this.currentSizeExtract * 20 / this.totalSizeExtract);
/* 706 */        this.subtaskMessage = ("Extracting: " + entry.getName() + " " + this.currentSizeExtract * 100 / this.totalSizeExtract + "%" );
/*    */      }
/*    */
/* 709 */      validateCertificateChain(certificate, entry.getCertificates());
/*    */
/* 711 */      in.close();
/* 712 */      out.close();
/*    */    }
/* 714 */    this.subtaskMessage = "";
/*    */
/* 716 */    jarFile.close();
/*    */
/* 718 */    File f = new File(path + nativeJar);
/* 719 */    f.delete();
/*    */  }
/*    */
/*    */  protected static void validateCertificateChain(Certificate[] ownCerts, Certificate[] native_certs)
/*    */    throws Exception
/*    */  {
/* 729 */    if (ownCerts == null) return;
/* 730 */    if (native_certs == null) throw new Exception("Unable to validate certificate chain. Native entry did not have a certificate chain at all" );
/*    */
/* 732 */    if (ownCerts.length != native_certs.length) throw new Exception("Unable to validate certificate chain. Chain differs in length [" + ownCerts.length + " vs " + native_certs.length + "]" );
/*    */
/* 734 */    for (int i = 0; i < ownCerts.length; i++)
/* 735 */      if (!ownCerts[i].equals(native_certs[i]))
/* 736 */        throw new Exception("Certificate mismatch: " + ownCerts[i] + " != " + native_certs[i]);
/*    */  }
/*    */
/*    */  protected String getJarName(URL url)
/*    */  {
/* 742 */    String fileName = url.getFile();
/*    */
/* 744 */    if (fileName.contains("?" )) {
/* 745 */      fileName = fileName.substring(0, fileName.indexOf("?" ));
/*    */    }
/* 747 */    if (fileName.endsWith(".pack.lzma" ))
/* 748 */      fileName = fileName.replaceAll(".pack.lzma", "" );
/* 749 */    else if (fileName.endsWith(".pack" ))
/* 750 */      fileName = fileName.replaceAll(".pack", "" );
/* 751 */    else if (fileName.endsWith(".lzma" )) {
/* 752 */      fileName = fileName.replaceAll(".lzma", "" );
/*    */    }
/*    */
/* 755 */    return fileName.substring(fileName.lastIndexOf('/') + 1);
/*    */  }
/*    */
/*    */  protected String getFileName(URL url) {
/* 759 */    String fileName = url.getFile();
/* 760 */    if (fileName.contains("?" )) {
/* 761 */      fileName = fileName.substring(0, fileName.indexOf("?" ));
/*    */    }
/* 763 */    return fileName.substring(fileName.lastIndexOf('/') + 1);
/*    */  }
/*    */
/*    */  protected void fatalErrorOccured(String error, Exception e) {
/* 767 */    e.printStackTrace();
/* 768 */    this.fatalError = true;
/* 769 */    this.fatalErrorDescription = ("Fatal error occured (" + this.state + " ): " + error);
/* 770 */    System.out.println(this.fatalErrorDescription);
/* 771 */    if (e != null)
/* 772 */      System.out.println(generateStacktrace(e));
/*    */  }
/*    */
/*    */  public boolean canPlayOffline()
/*    */  {
/*    */    try
/*    */    {
/* 779 */      String path = (String)AccessController.doPrivileged(new PrivilegedExceptionAction() {
/*    */        public Object run() throws Exception {
/* 781 */          return Util.getWorkingDirectory() + File.separator + "bin" + File.separator;
/*    */        }
/*    */      });
/* 785 */      File dir = new File(path);
/* 786 */      if (!dir.exists()) return false;
/*    */
/* 788 */      dir = new File(dir, "version" );
/* 789 */      if (!dir.exists()) return false;
/*    */
/* 791 */      if (dir.exists()) {
/* 792 */        String version = readVersionFile(dir);
/* 793 */        if ((version != null) && (version.length() > 0))
/* 794 */          return true;
/*    */      }
/*    */    }
/*    */    catch (Exception e) {
/* 798 */      e.printStackTrace();
/* 799 */      return false;
/*    */    }
/* 801 */    return false;
/*    */  }
/*    */ }

n°2144747
julesm74
noobi
Posté le 06-06-2012 à 11:34:13  profilanswer
 

Je voulais savoir quel code je peut ajouté et ou le mettre dans se code.
 
je suis désolé dans demandé beaucoup mais je suis vraiment débutant en java j'aimerai vraiment mettre cette musique dans ma prochaine version de launcher.
 
Voila le launcher pour avec le code source complet vous pouvez le décompilé www.horyzon.eu/ressources/Launcher_Horyzon.jar

n°2144750
likesum41
Posté le 06-06-2012 à 11:55:22  profilanswer
 

Je crois qu'il existe une classe en JAVA (trouvable sur le net) qui te permet de lire une musique.
 
Tiens, la voilà (enfin je crois):
http://www.commentcamarche.net/for [...] io-en-java
c'est au 2eme poste.
 
ensuite il suffit de le mettre dans le même répertoire (ou package) et de faire appel a la fonction qui lit la musique dans le constructeur de ton launcher.

n°2144753
julesm74
noobi
Posté le 06-06-2012 à 12:18:46  profilanswer
 

Vraiment merci pour ton aide je vais testé sa tous de suite.

n°2144756
julesm74
noobi
Posté le 06-06-2012 à 12:31:14  profilanswer
 

Si j'ai bien compris je mais se code dans une classe dans mon package
import java.io.DataInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
 
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.SourceDataLine;
 
public class Sound {
 
 private AudioFormat format;
 
 private byte[] samples;
 
 public Sound(String filename) {
  try {
   AudioInputStream stream = AudioSystem.getAudioInputStream(new File(filename));
   format = stream.getFormat();
   samples = getSamples(stream);
  } catch (Exception e) {
  }
 }
 
 public byte[] getSamples() {
  return samples;
 }
 
 public byte[] getSamples(AudioInputStream stream) {
  int length = (int) (stream.getFrameLength() * format.getFrameSize());
  byte[] samples = new byte[length];
  DataInputStream in = new DataInputStream(stream);
  try {
   in.readFully(samples);
  } catch (Exception e) {
  }
  return samples;
 }
 
 public void play(InputStream source) {
  int bufferSize = format.getFrameSize() * Math.round(format.getSampleRate() / 10);
  byte[] buffer = new byte[bufferSize];
  SourceDataLine line;
  try {
   DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
   line = (SourceDataLine) AudioSystem.getLine(info);
   line.open(format, bufferSize);
  } catch (LineUnavailableException e) {
   e.printStackTrace();
   return;
  }
  line.start();
  try {
   int numBytesRead = 0;
   while (numBytesRead != -1) {
    numBytesRead = source.read(buffer, 0, buffer.length);
    if (numBytesRead != -1)
     line.write(buffer, 0, numBytesRead);
   }
  } catch (IOException e) {
   e.printStackTrace();
  }
  line.drain();
  line.close();
 }
}
 
 
A l'endroit de mon code ou je veut que sa démarre la musique
je mais se code:
 
Sound player = new Sound("ton fichier.wav" );
InputStream stream = new ByteArrayInputStream(player.getSamples());
player.play(stream);
 
 
Je me trompe?

n°2144757
julesm74
noobi
Posté le 06-06-2012 à 12:42:00  profilanswer
 

après avoir testé cela ne marche pas j'ai du me trompé quelque par
voila le code que j'ai mis dans le classe dite moi si je me suis trompé
 
 
/*     */ package net.minecraft;
/*     */  
/*     */ import java.awt.BorderLayout;
/*     */ import java.awt.Color;
/*     */ import java.awt.Dimension;
/*     */ import java.awt.Frame;
/*     */ import java.awt.event.WindowAdapter;
/*     */ import java.awt.event.WindowEvent;
import java.io.ByteArrayInputStream;
/*     */ import java.io.IOException;
import java.io.InputStream;
/*     */ import java.io.PrintStream;
/*     */ import java.net.URLEncoder;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ import javax.imageio.ImageIO;
/*     */ import javax.swing.JPanel;
/*     */ import javax.swing.JPasswordField;
/*     */ import javax.swing.JTextField;
import javax.swing.UIManager;
/*     */  
/*     */ public class LauncherFrame extends Frame
/*     */ {
/*     */   public static final int VERSION = 13;
/*     */   private static final long serialVersionUID = 1L;
/*  21 */   public Map<String, String> customParameters = new HashMap();
/*     */   public Launcher launcher;
/*     */   public LoginForm loginForm;
/*     */  
/*     */   public LauncherFrame()
/*     */   {
/*  27 */     super("Horyzon" );
/*     */  
/*  29 */     setBackground(Color.BLACK);
/*  30 */     this.loginForm = new LoginForm(this);
/*  31 */     JPanel p = new JPanel();
/*  32 */     p.setLayout(new BorderLayout());
/*  33 */     p.add(this.loginForm, "Center" );
/*     */  
/*  35 */     p.setPreferredSize(new Dimension(854, 480));
/*     */  
/*  37 */     setLayout(new BorderLayout());
/*  38 */     add(p, "Center" );
/*     */  
/*  40 */     pack();
/*  41 */     setLocationRelativeTo(null);
/*     */     try
/*     */     {
/*  44 */       setIconImage(ImageIO.read(LauncherFrame.class.getResource("favicon.png" )));
/*     */     } catch (IOException e1) {
/*  46 */       e1.printStackTrace();
/*     */     }
/*     */  
/*  49 */     addWindowListener(new WindowAdapter() {
/*     */       public void windowClosing(WindowEvent arg0) {
/*  51 */         new Thread() {
/*     */           public void run() {
/*     */             try {
/*  54 */               Thread.sleep(30000L);
/*     */             } catch (InterruptedException e) {
/*  56 */               e.printStackTrace();
/*     */             }
/*  58 */             System.out.println("FORCING EXIT!" );
/*  59 */             System.exit(0);
/*     */           }
/*     */         }
/*  62 */         .start();
/*  63 */         if (LauncherFrame.this.launcher != null) {
/*  64 */           LauncherFrame.this.launcher.stop();
/*  65 */           LauncherFrame.this.launcher.destroy();
/*     */         }
/*  67 */         System.exit(0);
/*     */       } } );
/*     */   }
/*     */  
/*     */   public void playCached(String userName) {
/*     */     try {
/*  74 */       if ((userName == null) || (userName.length() <= 0)) {
/*  75 */         userName = "Player";
/*     */       }
/*  77 */       this.launcher = new Launcher();
/*  78 */       this.launcher.customParameters.putAll(this.customParameters);
/*  79 */       this.launcher.customParameters.put("userName", userName);
/*  80 */       this.launcher.init();
/*  81 */       removeAll();
/*  82 */       add(this.launcher, "Center" );
/*  83 */       validate();
/*  84 */       this.launcher.start();
/*  85 */       this.loginForm = null;
/*  86 */       setTitle("Horyzon" );
/*     */     } catch (Exception e) {
/*  88 */       e.printStackTrace();
/*  89 */       showError(e.toString());
/*     */     }
/*     */   }
/*     */  
/*     */   public void login(String userName, String password) {
/*     */     try {
/*  95 */       String parameters = "user=" + URLEncoder.encode(userName, "UTF-8" ) + "&password=" + URLEncoder.encode(password, "UTF-8" ) + "&version=" + 13;
/*  96 */       String result = Util.excutePost("https://login.minecraft.net/", parameters);
/*  97 */       if (result == null) {
/*  98 */         showError("Impossible de se connecter à minecraft.net" );
/*  99 */         this.loginForm.setNoNetwork();
/* 100 */         return;
/*     */       }
/* 102 */       if (!result.contains(":" )) {
/* 103 */         if (result.trim().equals("Mauvais mot de passe" )) {
/* 104 */           showError("Echec de l'identification" );
/* 105 */         } else if (result.trim().equals("Trop vieille version du Launcher" )) {
/* 106 */           this.loginForm.setOutdated();
/* 107 */           showError("Trop vieille version du Launcher" );
/*     */         } else {
/* 109 */           showError(result);
/*     */         }
/* 111 */         this.loginForm.setNoNetwork();
/* 112 */         return;
/*     */       }
/* 114 */       String[] values = result.split(":" );
/*     */  
/* 116 */       this.launcher = new Launcher();
/* 117 */       this.launcher.customParameters.putAll(this.customParameters);
/* 118 */       this.launcher.customParameters.put("userName", values[2].trim());
/* 119 */       this.launcher.customParameters.put("latestVersion", values[0].trim());
/* 120 */       this.launcher.customParameters.put("downloadTicket", values[1].trim());
/* 121 */       this.launcher.customParameters.put("sessionId", values[3].trim());
/* 122 */       this.launcher.init();
/*     */  
/* 124 */       removeAll();
/* 125 */       add(this.launcher, "Center" );
/* 126 */       validate();
/* 127 */       this.launcher.start();
/* 128 */       this.loginForm.loginOk();
/* 129 */       this.loginForm = null;
/* 130 */       setTitle("Horyzon" );
/*     */     } catch (Exception e) {
/* 132 */       e.printStackTrace();
/* 133 */       showError(e.toString());
/* 134 */       this.loginForm.setNoNetwork();
/*     */     }
/*     */   }
/*     */  
/*     */   private void showError(String error) {
/* 139 */     removeAll();
/* 140 */     add(this.loginForm);
/* 141 */     this.loginForm.setError(error);
/* 142 */     validate();
/*     */   }
/*     */  
/*     */   public boolean canPlayOffline(String userName) {
/* 146 */     Launcher launcher = new Launcher();
/* 147 */     launcher.customParameters.putAll(this.customParameters);
/* 148 */     launcher.init(userName, null, null, null);
/* 149 */     return launcher.canPlayOffline();
/*     */   }
/*     */  
/*     */   public static void main(String[] args) {
/*     */     try {
/* 154 */       UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
/*     */     }
/*     */     catch (Exception localException) {
/*     */     }
/* 158 */     LauncherFrame launcherFrame = new LauncherFrame();
/* 159 */     launcherFrame.setVisible(true);
/* 160 */     launcherFrame.customParameters.put("stand-alone", "true" );
/*     */  
/* 162 */     if (args.length >= 3) {
/* 163 */       String ip = args[2];
/* 164 */       String port = "25565";
/* 165 */       if (ip.contains(":" )) {
/* 166 */         String[] parts = ip.split(":" );
/* 167 */         ip = parts[0];
/* 168 */         port = parts[1];
/*     */       }
/*     */  
/* 171 */       launcherFrame.customParameters.put("server", ip);
/* 172 */       launcherFrame.customParameters.put("port", port);
/*     */     }
/*     */  
/* 175 */     if (args.length >= 1) {
/* 176 */       launcherFrame.loginForm.userName.setText(args[0]);
/* 177 */       if (args.length >= 2) {
/* 178 */         launcherFrame.loginForm.password.setText(args[1]);
/* 179 */         launcherFrame.loginForm.doLogin();
/*     */       }
 
 
 
Music player = new Music("Jingle-Staby.wav" );
InputStream stream = new ByteArrayInputStream(player.getSamples());
player.play(stream);
 
 
 
/*     */     }
/*     */   }
/*     */ }
 
/* Location:           C:\Documents and Settings\FLEJA\Bureau\minecraft.jar
 * Qualified Name:     net.minecraft.LauncherFrame
 * JD-Core Version:    0.6.0
 */

mood
Publicité
Posté le 06-06-2012 à 12:42:00  profilanswer
 

n°2144776
likesum41
Posté le 06-06-2012 à 13:50:38  profilanswer
 

en effet tu te trompes,  
 
essaie de le mettre dans cette fonction:
 
public LauncherFrame(){
***
***
***
}

n°2144786
julesm74
noobi
Posté le 06-06-2012 à 14:06:41  profilanswer
 

/*     */ package net.minecraft;
/*     */  
/*     */ import java.awt.BorderLayout;
/*     */ import java.awt.Color;
/*     */ import java.awt.Dimension;
/*     */ import java.awt.Frame;
/*     */ import java.awt.event.WindowAdapter;
/*     */ import java.awt.event.WindowEvent;
import java.io.ByteArrayInputStream;
/*     */ import java.io.IOException;
import java.io.InputStream;
/*     */ import java.io.PrintStream;
/*     */ import java.net.URLEncoder;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ import javax.imageio.ImageIO;
/*     */ import javax.swing.JPanel;
/*     */ import javax.swing.JPasswordField;
/*     */ import javax.swing.JTextField;
import javax.swing.UIManager;
/*     */  
/*     */ public class LauncherFrame extends Frame
/*     */ {
/*     */   public static final int VERSION = 13;
/*     */   private static final long serialVersionUID = 1L;
/*  21 */   public Map<String, String> customParameters = new HashMap();
/*     */   public Launcher launcher;
/*     */   public LoginForm loginForm;
/*     */  
/*     */   public LauncherFrame()
/*     */   {
/*  27 */     super("Horyzon" );
/*     */  
/*  29 */     setBackground(Color.BLACK);
/*  30 */     this.loginForm = new LoginForm(this);
/*  31 */     JPanel p = new JPanel();
/*  32 */     p.setLayout(new BorderLayout());
/*  33 */     p.add(this.loginForm, "Center" );
/*     */  
/*  35 */     p.setPreferredSize(new Dimension(854, 480));
/*     */  
/*  37 */     setLayout(new BorderLayout());
/*  38 */     add(p, "Center" );
/*     */  
/*  40 */     pack();
/*  41 */     setLocationRelativeTo(null);
/*     */     try
/*     */     {
/*  44 */       setIconImage(ImageIO.read(LauncherFrame.class.getResource("favicon.png" )));
/*     */     } catch (IOException e1) {
/*  46 */       e1.printStackTrace();
/*     */     }
/*     */  
/*  49 */     addWindowListener(new WindowAdapter() {
/*     */       public void windowClosing(WindowEvent arg0) {
/*  51 */         new Thread() {
/*     */           public void run() {
/*     */             try {
/*  54 */               Thread.sleep(30000L);
/*     */             } catch (InterruptedException e) {
/*  56 */               e.printStackTrace();
/*     */             }
/*  58 */             System.out.println("FORCING EXIT!" );
/*  59 */             System.exit(0);
/*     */           }
/*     */         }
/*  62 */         .start();
/*  63 */         if (LauncherFrame.this.launcher != null) {
/*  64 */           LauncherFrame.this.launcher.stop();
/*  65 */           LauncherFrame.this.launcher.destroy();
/*     */         }
/*  67 */         System.exit(0);
/*     */       } } );
/*     */   }
/*     */  
/*     */   public void playCached(String userName) {
/*     */     try {
/*  74 */       if ((userName == null) || (userName.length() <= 0)) {
/*  75 */         userName = "Player";
/*     */       }
/*  77 */       this.launcher = new Launcher();
/*  78 */       this.launcher.customParameters.putAll(this.customParameters);
/*  79 */       this.launcher.customParameters.put("userName", userName);
/*  80 */       this.launcher.init();
/*  81 */       removeAll();
/*  82 */       add(this.launcher, "Center" );
/*  83 */       validate();
/*  84 */       this.launcher.start();
/*  85 */       this.loginForm = null;
/*  86 */       setTitle("Horyzon" );
/*     */     } catch (Exception e) {
/*  88 */       e.printStackTrace();
/*  89 */       showError(e.toString());
/*     */     }
/*     */   }
/*     */  
/*     */   public void login(String userName, String password) {
/*     */     try {
/*  95 */       String parameters = "user=" + URLEncoder.encode(userName, "UTF-8" ) + "&password=" + URLEncoder.encode(password, "UTF-8" ) + "&version=" + 13;
/*  96 */       String result = Util.excutePost("https://login.minecraft.net/", parameters);
/*  97 */       if (result == null) {
/*  98 */         showError("Impossible de se connecter à minecraft.net" );
/*  99 */         this.loginForm.setNoNetwork();
/* 100 */         return;
/*     */       }
/* 102 */       if (!result.contains(":" )) {
/* 103 */         if (result.trim().equals("Mauvais mot de passe" )) {
/* 104 */           showError("Echec de l'identification" );
/* 105 */         } else if (result.trim().equals("Trop vieille version du Launcher" )) {
/* 106 */           this.loginForm.setOutdated();
/* 107 */           showError("Trop vieille version du Launcher" );
/*     */         } else {
/* 109 */           showError(result);
/*     */         }
/* 111 */         this.loginForm.setNoNetwork();
/* 112 */         return;
/*     */       }
/* 114 */       String[] values = result.split(":" );
/*     */  
/* 116 */       this.launcher = new Launcher();
/* 117 */       this.launcher.customParameters.putAll(this.customParameters);
/* 118 */       this.launcher.customParameters.put("userName", values[2].trim());
/* 119 */       this.launcher.customParameters.put("latestVersion", values[0].trim());
/* 120 */       this.launcher.customParameters.put("downloadTicket", values[1].trim());
/* 121 */       this.launcher.customParameters.put("sessionId", values[3].trim());
/* 122 */       this.launcher.init();
/*     */  
/* 124 */       removeAll();
/* 125 */       add(this.launcher, "Center" );
/* 126 */       validate();
/* 127 */       this.launcher.start();
/* 128 */       this.loginForm.loginOk();
/* 129 */       this.loginForm = null;
/* 130 */       setTitle("Horyzon" );
/*     */     } catch (Exception e) {
/* 132 */       e.printStackTrace();
/* 133 */       showError(e.toString());
/* 134 */       this.loginForm.setNoNetwork();
/*     */     }
/*     */   }
/*     */  
/*     */   private void showError(String error) {
/* 139 */     removeAll();
/* 140 */     add(this.loginForm);
/* 141 */     this.loginForm.setError(error);
/* 142 */     validate();
/*     */   }
/*     */  
/*     */   public boolean canPlayOffline(String userName) {
/* 146 */     Launcher launcher = new Launcher();
/* 147 */     launcher.customParameters.putAll(this.customParameters);
/* 148 */     launcher.init(userName, null, null, null);
/* 149 */     return launcher.canPlayOffline();
/*     */   }
/*     */  
/*     */   public static void main(String[] args) {
/*     */     try {
/* 154 */       UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
/*     */     }
/*     */     catch (Exception localException) {
/*     */     }
/* 158 */     LauncherFrame launcherFrame = new LauncherFrame();
/* 159 */     launcherFrame.setVisible(true);
/* 160 */     launcherFrame.customParameters.put("stand-alone", "true" );
/*     */  
/* 162 */     if (args.length >= 3) {
/* 163 */       String ip = args[2];
/* 164 */       String port = "25565";
/* 165 */       if (ip.contains(":" )) {
/* 166 */         String[] parts = ip.split(":" );
/* 167 */         ip = parts[0];
/* 168 */         port = parts[1];
/*     */       }
/*     */  
/* 171 */       launcherFrame.customParameters.put("server", ip);
/* 172 */       launcherFrame.customParameters.put("port", port);
/*     */     }
/*     */  
/* 175 */     if (args.length >= 1) {
/* 176 */       launcherFrame.loginForm.userName.setText(args[0]);
/* 177 */       if (args.length >= 2) {
/* 178 */         launcherFrame.loginForm.password.setText(args[1]);
/* 179 */         launcherFrame.loginForm.doLogin();
/*     */   }    
}
}
 
public void LauncherFrame1(){
 Music player = new Music("Jingle-Staby.wav" );
 InputStream stream = new ByteArrayInputStream(player.getSamples());
 player.play(stream);  
 
/*     */     }
 
 
 
 
 
 
j'ai du rajouter void sur ton code sinon il me m’étais une erreur
 
la j'ai test le launcher démarre mais toujours pas de son
je me suis peut être trompé de classe non?
 
si vous avez le temps vous pouvez décompiler le launcher (lien plus haut) et me dire dans quel classe il faut que je mette le code
 
Je suis désolé de demandé beaucoup de choses mais se truc me tien à coeur.
 
 
/*     */    
/*     */ }

n°2144788
likesum41
Posté le 06-06-2012 à 14:09:17  profilanswer
 

^^
 
A la ligne 25 tu as:
public LauncherFrame()  
 
je parlait de cette fonction la.
ressaie de placer ce code:
 
Music player = new Music("Jingle-Staby.wav" );
 InputStream stream = new ByteArrayInputStream(player.getSamples());
 player.play(stream);
 
à la ligne 28 par exemple.

n°2144791
likesum41
Posté le 06-06-2012 à 14:12:12  profilanswer
 

en faite je ne sais pas si tu le sais mais je vais t'expliquer une petite chose. T'as classe s'appelle "LauncherFrame"
 
Automatiquement, si tu a une fonction qui porte le meme nom que t'as classe (ici, public LauncherFrame(){}), le code à l'intérieur sera exécuté lorsque tu instanciera cet objet.
 
Mettre ton code dans cette fonction fera que ta musique sera lancée dès l'ouverture de ta frame.

n°2144796
julesm74
noobi
Posté le 06-06-2012 à 14:14:23  profilanswer
 

j'ai fait comme tu la dit mais j'ai une erreur à  
/*  27 */     super("Horyzon" );
Il et souligné en rouge.
 
 
 
 
/*     */ package net.minecraft;
/*     */  
/*     */ import java.awt.BorderLayout;
/*     */ import java.awt.Color;
/*     */ import java.awt.Dimension;
/*     */ import java.awt.Frame;
/*     */ import java.awt.event.WindowAdapter;
/*     */ import java.awt.event.WindowEvent;
import java.io.ByteArrayInputStream;
/*     */ import java.io.IOException;
import java.io.InputStream;
/*     */ import java.io.PrintStream;
/*     */ import java.net.URLEncoder;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ import javax.imageio.ImageIO;
/*     */ import javax.swing.JPanel;
/*     */ import javax.swing.JPasswordField;
/*     */ import javax.swing.JTextField;
import javax.swing.UIManager;
/*     */  
/*     */ public class LauncherFrame extends Frame
/*     */ {
/*     */   public static final int VERSION = 13;
/*     */   private static final long serialVersionUID = 1L;
/*  21 */   public Map<String, String> customParameters = new HashMap();
/*     */   public Launcher launcher;
/*     */   public LoginForm loginForm;
/*     */  
/*     */   public LauncherFrame()
{
/*     */    Music player = new Music("Jingle-Staby.wav" );
/*     */    InputStream stream = new ByteArrayInputStream(player.getSamples());
/*     */    player.play(stream);  
 
/*     */    
/*  27 */     super("Horyzon" );
/*     */  
/*  29 */     setBackground(Color.BLACK);
/*  30 */     this.loginForm = new LoginForm(this);
/*  31 */     JPanel p = new JPanel();
/*  32 */     p.setLayout(new BorderLayout());
/*  33 */     p.add(this.loginForm, "Center" );
/*     */  
/*  35 */     p.setPreferredSize(new Dimension(854, 480));
/*     */  
/*  37 */     setLayout(new BorderLayout());
/*  38 */     add(p, "Center" );
/*     */  
/*  40 */     pack();
/*  41 */     setLocationRelativeTo(null);
/*     */     try
/*     */     {
 
 

n°2144797
likesum41
Posté le 06-06-2012 à 14:18:03  profilanswer
 

non tu as pas fait exactement comme j'ai dit ;) je t'ai conseillé la ligne 28

n°2144801
julesm74
noobi
Posté le 06-06-2012 à 14:25:06  profilanswer
 

je les ajouté mais au démarrage du launcher j'ai sa dans les log.
 
Exception in thread "main" java.lang.NullPointerException
 at java.io.ByteArrayInputStream.<init>(Unknown Source)
 at net.minecraft.LauncherFrame.<init>(LauncherFrame.java:36)
 at net.minecraft.LauncherFrame.main(LauncherFrame.java:169)

n°2144802
likesum41
Posté le 06-06-2012 à 14:28:29  profilanswer
 

tente ligne 153.
 
avant le try.
 
Je suis pas chez moi donc je peux pas tester par moi-même. c'est bien dommage

n°2144804
julesm74
noobi
Posté le 06-06-2012 à 14:29:38  profilanswer
 

ok je test et je te remercie vraiment de m'aider.

n°2144807
julesm74
noobi
Posté le 06-06-2012 à 14:32:36  profilanswer
 

je démarre pas d'erreur mais toujours pas de musique

n°2144808
julesm74
noobi
Posté le 06-06-2012 à 14:34:26  profilanswer
 

il faut peut être le mettre dans une autres classe non?
 
Sinon tu sera cher toi quand comme sa tu pourr

n°2144810
likesum41
Posté le 06-06-2012 à 14:36:33  profilanswer
 

Compiles tu bien ton jar avec ton son wav et le place tu bien? ( je pense que tu dois le mettre dans le même package que les classes si tu veux mettre "Jingle-Staby.wav" )

n°2144811
julesm74
noobi
Posté le 06-06-2012 à 14:37:10  profilanswer
 

désolé bug d’envoi, je disais tu sera cher toi quand pour pouvoir tester?
 

n°2144814
julesm74
noobi
Posté le 06-06-2012 à 14:40:38  profilanswer
 

Oui je place la musique au même endroit que les classe et je compile en java exécutable et je  démarre mais pas de music

n°2144815
likesum41
Posté le 06-06-2012 à 14:42:29  profilanswer
 

Je vais tenter de me trouver un peu de temps ce soir mais je ne peux rien te promettre.

n°2144819
julesm74
noobi
Posté le 06-06-2012 à 14:55:41  profilanswer
 

ok merci
si jamais mon skype: julesm123456

n°2144989
julesm74
noobi
Posté le 07-06-2012 à 11:42:31  profilanswer
 

Ta u le temps de regardé?

n°2145012
likesum41
Posté le 07-06-2012 à 14:12:36  profilanswer
 

Non, j'ai pas eu le temps mais ce que tu peux faire, c'est m'envoyer directement les .java et non les .class. (les fichiers non-compilés)
 
Décompiler ce type de fichier ne marche pas souvent et ça sera une démarche en moins a faire ;)

n°2145057
julesm74
noobi
Posté le 07-06-2012 à 19:05:23  profilanswer
 

Voilà les source du plugin en .zip  
http://www.horyzon.eu/launcher.zip
 
ta juste à décompresser et modifier le launcher_HQ

n°2145069
julesm74
noobi
Posté le 07-06-2012 à 21:08:20  profilanswer
 

fail launcher pardon :)

n°2145148
julesm74
noobi
Posté le 08-06-2012 à 15:30:24  profilanswer
 

Ta u le temps de tester?
Sinon tu peut me dire quand tu aura le temps rien ne presse mais c juste pour savoir si je vais intégré la music dans la prochain version du launcher.
ou dans une encore autres version.

n°2145240
julesm74
noobi
Posté le 10-06-2012 à 01:10:12  profilanswer
 

Salut,
Je vient de réussir à le faire pour mettre la music merci beaucoup pour m'avoir aider ;)

n°2145303
likesum41
Posté le 11-06-2012 à 10:12:47  profilanswer
 

Mince, tu m'as pris au dépourvu ^^'
 
Et donc, as-tu utilisé la classe que je t'avais donné ou alors tu as pris une autre manière?

n°2145589
julesm74
noobi
Posté le 12-06-2012 à 20:48:05  profilanswer
 

désolé pour temps d'attente long
 
Alors j'ai trouvé un autres code
package net.minecraft;
 
import   java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
 
import javax.sound.sampled.*;
 
 
public class Audio extends Thread{
   protected URL[] urlList;
 
   AudioInputStream audioInputStream = null;
   SourceDataLine line;
 
   public void run(){
      File fichier =  new File("Jingle-Staby.wav" );
      try {
      AudioFileFormat format = AudioSystem.getAudioFileFormat(fichier);
      } catch (UnsupportedAudioFileException e1) {
         e1.printStackTrace();
      } catch (IOException e1) {
         e1.printStackTrace();
      }
 
      try {
         audioInputStream = AudioSystem.getAudioInputStream(fichier);
      } catch (UnsupportedAudioFileException e) {
         e.printStackTrace();
      } catch (IOException e) {
         e.printStackTrace();
      }
 
       AudioFormat audioFormat = audioInputStream.getFormat();
       DataLine.Info info = new DataLine.Info(SourceDataLine.class,audioFormat);
 
       try {
          line = (SourceDataLine) AudioSystem.getLine(info);
 
          } catch (LineUnavailableException e) {
            e.printStackTrace();
            return;
          }
 
      try {
            line.open(audioFormat);
      } catch (LineUnavailableException e) {
               e.printStackTrace();
               return;
      }
      line.start();
      try {
         byte bytes[] = new byte[1024];
         int bytesRead=0;
         while ((bytesRead = audioInputStream.read(bytes, 0, bytes.length)) != -1) {
              line.write(bytes, 0, bytesRead);
              }
      } catch (IOException io) {
         io.printStackTrace();
         return;
      }
   }
}
 
 
 
Et j'ai tous simplement mis se code pour démarre la musique
Audio son = new Audio();
son.start();
Au emplacement que tu ma conseiller et miracle sa marche :)

mood
Publicité
Posté le   profilanswer
 


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Java

  Besoin d'aide java

 

Sujets relatifs
besoin d'aide pb JAVA declaration impots + videos SVPbesoin d'aide pour debutant java
stp j'ai besoin d'aide sur les évènements dans javabesoin d'aide en java ?
Java Mysql besoin d'aideBesoin d'aide, conseil Jsp, java
[java] debutant besoin d'aide pour interface graphBesoin d'aide pour traiter une image en java
besoin d'aide pour executer du java[Java] Besoin d'aide pour petits progs de debutante
Plus de sujets relatifs à : Besoin d'aide java


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR