PDA

View Full Version : [508] Custom Login Music [508]



UnitedScape
June 19th, 2010, 06:45
i like this forum so i going to start distributing stuff.

The only problem with this is the sound control is broken and i can't figure out how to add it properly (can't find interface values)

Difficulty: 4/10

This doesn't play MP3s but it can if you put in an API.

Supported file types can be found here: Only the registered members can see the link.

Files edited:
Class35_Sub2.java
Login.java

Files created:
MusicPlayer.java
Stopper.java

Class35_Sub2.java
Open Class35_Sub2.java and search for:
Code:


public void method423(int paramInt) throws LineUnavailableException {

You should see:
Code:


public void method423(int paramInt) throws LineUnavailableException {
try {
DataLine.Info localInfo = new DataLine.Info(aClass2727, this.anAudioFormat2723, paramInt << 2);

this.aSourceDataLine2722 = ((SourceDataLine)AudioSystem.getLine(localInfo));
this.aSourceDataLine2722.open();
this.aSourceDataLine2722.start();
this.anInt2725 = paramInt;
} catch (LineUnavailableException localLineUnavailableException) {
if ((Class68_Sub20_Sub19.method1188(paramInt, -73) ^ 0xFFFFFFFF) != -2)
{
method423(Class90.method1517(paramInt, -21189));
} else {
this.aSourceDataLine2722 = null;
throw localLineUnavailableException;
}
}
}

Change this to:
Code:


public void method423(int paramInt) throws LineUnavailableException {
if (player == null) {
player = new MusicPlayer(new File("./music" + random(1, 4)+ ".wav"), true);
}
}

NOTE: Change the file name and extension to suit your music files.
Change 4 to the number of music files you have.

Then add the method:
Code:


public int random(int a, int b) {
return (int) (Math.random() * (b - a + 1)) + a;
}

Now you need to add the player at the top of the class:
Code:


public static MusicPlayer player;

And the import:
Code:


import java.io.File;

Login.java
Open Login.java and search for:
Code:


public Class68 method1474(int paramInt) {

You should see:
Code:


public Class68 method1474(int paramInt) {
anInt1518 += 1;
if (paramInt != 0)
aRSString_1507 = null;
return this.aClass113_1519.method1679(-32642);
}

Change this to:
Code:


public Class68 method1474(int paramInt) {
anInt1518++;
if (paramInt != 0) aRSString_1507 = null;
if (!startedStopper) {
new Stopper(Class35_Sub2.player);
startedStopper = true;
}
return aClass113_1519.method1679(-32642);
}

Now you need to add the boolean at the top of the class:
Code:


public boolean startedStopper;

MusicPlayer.java
Now you need to create the new class: MusicPlayer.java
Open up the new class and paste in:
Code:


import java.io.File;

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.FloatControl;
import javax.sound.sampled.SourceDataLine;

public class MusicPlayer extends Thread {
File file;
boolean loop;
FloatControl gainControl = null;

public MusicPlayer(File file, boolean loop) {
this.file = file;
this.loop = loop;
start();
}

public void run() {
while (loop) {
try {
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(file);
AudioFormat audioFormat = audioInputStream.getFormat();

DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat);
SourceDataLine line = (SourceDataLine) AudioSystem.getLine(info);
line.open(audioFormat);
line.start();
gainControl = (FloatControl) line.getControl(FloatControl.Type.MASTER_GAIN);

byte[] abData = new byte[128000]; // Buffer size [128000]
for (int nBytesRead = 0; nBytesRead >= 0;nBytesRead = audioInputStream.read(abData, 0, abData.length)) {
line.write(abData, 0, nBytesRead);
}

line.drain();
line.close();
} catch (Exception e) {
loop = false;
}
}
}

public void setVolume(int percent) {
if (gainControl != null && percent >= 0 && percent <= 100) {
gainControl.setValue((float) (Math.log(percent / 100.0) / Math.log(10.0) * 20.0));
}
}

public int getVolume() {
if (gainControl != null) {
return (int) (Math.exp(gainControl.getValue() * (Math.log(10.0) * 20.0)) * 100.0);
} else {
return 0;
}
}
}

Stopper.java
Now you need to create the new class: Stopper.java
Open up the new class and paste in:
Code:


public class Stopper extends Thread {
MusicPlayer player;

public Stopper(MusicPlayer player) {
this.player = player;
start();
}

public void run() {
try {
player.loop = false;
for (int v = player.getVolume(); v >= 0; v--) {
player.setVolume(v);
sleep(40); // lower number means a faster fade (40 recommended)
}
player.interrupt();
} catch (InterruptedException p) {}
}
}

NOTE: You may change the sleep for faster/slower fading.

Now you are ready to set up your music files!

Save the 4 files and go to your client file's folder.
After converting your files to one of the supported types, rename them to music1, music2, music3, etc...

All your music files have to use the same extension (I use .wav files).

Place all your files in your client's files folder and your done!

NOTE: Make sure you have the number of files in the Class35_Sub2.java method. (it is commented + noted above)

Don't leech this tutorial!

Faab234
June 19th, 2010, 09:19
Wow, Nice job UnitedScape.

Nathan'
June 19th, 2010, 09:27
Thank you, but most people will be like this is to much effort for songs etc as most ppl jus listen online

Thanks for posting and I didnt intend to flame anyone

UnitedScape
June 21st, 2010, 05:54
Thanks Faab

icedice
June 29th, 2010, 04:49
wow very nice. mind posting a list of compatible extensions? that would be nice!