Add a background music player to Mage Client. Music support .mp3 or .wav files. Put the audio files under plugins\sounds\music, random song will be played sequentially when GamePane is activited. the UI to adjust background music is add to preference dialog as well.

This commit is contained in:
Li REN 2013-06-12 22:55:25 -04:00
parent 7102d08637
commit 6bbaa9fda1
6 changed files with 78 additions and 20 deletions

View file

@ -123,6 +123,21 @@
<version>7.6.3</version>
<!--<scope>runtime</scope>-->
</dependency>
<dependency>
<groupId>com.googlecode.soundlibs</groupId>
<artifactId>mp3spi</artifactId>
<version>1.9.5-1</version>
</dependency>
<dependency>
<groupId>javazoom</groupId>
<artifactId>jlayer</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>org.mobicents.external.tritonus</groupId>
<artifactId>tritonus_share</artifactId>
<version>0.3.6</version>
</dependency>
</dependencies>
<build>

View file

@ -66,6 +66,7 @@ import mage.client.tournament.TournamentPanel;
import mage.client.util.EDTExceptionHandler;
import mage.client.util.SettingsManager;
import mage.client.util.gui.ArrowBuilder;
import mage.client.util.MusicPlayer;
import mage.components.ImagePanel;
import mage.interfaces.Action;
import mage.interfaces.MageClient;
@ -540,10 +541,14 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
ArrowBuilder.getBuilder().hideAllPanels();
if (frame instanceof GamePane) {
ArrowBuilder.getBuilder().showPanel(((GamePane) frame).getGameId());
MusicPlayer.playBGM();
}else{
MusicPlayer.stopBGM();
}
}
public static void deactivate(MagePane frame) {
MusicPlayer.stopBGM();
frame.setVisible(false);
MagePane topmost = getTopMost(frame);
if (activeFrame != frame) {

View file

@ -80,7 +80,8 @@ public final class Constants {
public static final String RESOURCE_PATH_SET = IO.imageBaseDir + "sets" + File.separator;
public static final String RESOURCE_PATH_SET_SMALL = RESOURCE_PATH_SET + File.separator + "small" + File.separator;
public static final String BASE_SOUND_PATH = "plugins" + File.separator + "sounds" + File.separator;
public static final String BASE_MUSICS_PATH = "plugins" + File.separator + "sounds" + File.separator + "musics" + File.separator ;
public interface IO {
String imageBaseDir = "plugins" + File.separator + "images" + File.separator;
String IMAGE_PROPERTIES_FILE = "image.url.properties";

View file

@ -1,4 +1,4 @@
<?xml version="1.1" encoding="UTF-8" ?>
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
<Properties>
@ -7,6 +7,7 @@
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
@ -25,7 +26,7 @@
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jTabbedPane1" alignment="0" max="32767" attributes="0"/>
<Group type="102" alignment="1" attributes="0">
<EmptySpace pref="316" max="32767" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="saveButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="exitButton" min="-2" pref="55" max="-2" attributes="0"/>
@ -81,7 +82,7 @@
<Component id="jPanel3" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="jPanel7" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="84" max="32767" attributes="0"/>
<EmptySpace pref="92" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -443,7 +444,7 @@
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jPanel5" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="92" max="32767" attributes="0"/>
<EmptySpace pref="96" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -562,7 +563,10 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="19" max="-2" attributes="0"/>
<Component id="jEnableSounds" min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jEnableSounds" min="-2" max="-2" attributes="0"/>
<Component id="jEnableMusics" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="325" max="32767" attributes="0"/>
</Group>
</Group>
@ -572,7 +576,9 @@
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="24" max="-2" attributes="0"/>
<Component id="jEnableSounds" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="217" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jEnableMusics" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="194" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -586,6 +592,14 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jEnableSoundsActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JCheckBox" name="jEnableMusics">
<Properties>
<Property name="text" type="java.lang.String" value="enable BGM"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jEnableMusicsActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="jPanel6">

View file

@ -73,6 +73,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
public static final String KEY_CARD_IMAGES_SAVE_TO_ZIP = "cardImagesSaveToZip";
public static final String KEY_SOUNDS_ON = "soundsOn";
public static final String KEY_MUSICS_ON = "MusicsOn";
public static final String KEY_BIG_CARD_TOGGLED = "bigCardToggled";
@ -201,6 +202,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
saveToZipFiles = new javax.swing.JCheckBox();
jPanel22 = new javax.swing.JPanel();
jEnableSounds = new javax.swing.JCheckBox();
jEnableMusics = new javax.swing.JCheckBox();
jPanel6 = new javax.swing.JPanel();
lblProxyType = new javax.swing.JLabel();
cbProxyType = new javax.swing.JComboBox();
@ -322,7 +324,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(84, Short.MAX_VALUE))
.addContainerGap(92, Short.MAX_VALUE))
);
jTabbedPane1.addTab("Main", jPanel1);
@ -537,7 +539,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
.addGroup(jPanel4Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(92, Short.MAX_VALUE))
.addContainerGap(96, Short.MAX_VALUE))
);
jTabbedPane1.addTab("Images", jPanel4);
@ -549,13 +551,22 @@ public class PreferencesDialog extends javax.swing.JDialog {
}
});
jEnableMusics.setText("enable BGM");
jEnableMusics.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jEnableMusicsActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel22Layout = new javax.swing.GroupLayout(jPanel22);
jPanel22.setLayout(jPanel22Layout);
jPanel22Layout.setHorizontalGroup(
jPanel22Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel22Layout.createSequentialGroup()
.addGap(19, 19, 19)
.addComponent(jEnableSounds)
.addGroup(jPanel22Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jEnableSounds)
.addComponent(jEnableMusics))
.addContainerGap(325, Short.MAX_VALUE))
);
jPanel22Layout.setVerticalGroup(
@ -563,7 +574,9 @@ public class PreferencesDialog extends javax.swing.JDialog {
.addGroup(jPanel22Layout.createSequentialGroup()
.addGap(24, 24, 24)
.addComponent(jEnableSounds)
.addContainerGap(217, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jEnableMusics)
.addContainerGap(194, Short.MAX_VALUE))
);
jTabbedPane1.addTab("Sounds", jPanel22);
@ -605,7 +618,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
}
});
jLabel11.setFont(new java.awt.Font("Tahoma", 2, 10));
jLabel11.setFont(new java.awt.Font("Tahoma", 2, 10)); // NOI18N
jLabel11.setText("Note: password won't be encrypted!");
javax.swing.GroupLayout pnlProxyLayout = new javax.swing.GroupLayout(pnlProxy);
@ -747,7 +760,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
.addGap(0, 100, Short.MAX_VALUE)
);
jLabel12.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel12.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
jLabel12.setText("Choose your avatar:");
jPanel12.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(204, 204, 204), 1, true));
@ -789,7 +802,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
.addGap(0, 100, Short.MAX_VALUE)
);
jLabel13.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel13.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
jLabel13.setText("New avatars:");
jPanel16.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(204, 204, 204), 1, true));
@ -975,7 +988,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTabbedPane1)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(316, Short.MAX_VALUE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(saveButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(exitButton, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
@ -1028,7 +1041,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
// sounds
save(prefs, dialog.jEnableSounds, KEY_SOUNDS_ON, "true", "false", UPDATE_CACHE_POLICY);
save(prefs, dialog.jEnableMusics, KEY_MUSICS_ON, "true", "false", UPDATE_CACHE_POLICY);
// connection
save(prefs, dialog.cbProxyType, KEY_PROXY_TYPE);
save(prefs, dialog.txtProxyServer, KEY_PROXY_ADDRESS);
@ -1124,6 +1137,10 @@ public class PreferencesDialog extends javax.swing.JDialog {
// TODO add your handling code here:
}//GEN-LAST:event_jEnableSoundsActionPerformed
private void jEnableMusicsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jEnableMusicsActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jEnableMusicsActionPerformed
private void showProxySettings() {
if (cbProxyType.getSelectedItem() == Connection.ProxyType.SOCKS) {
this.pnlProxy.setVisible(true);
@ -1231,6 +1248,12 @@ public class PreferencesDialog extends javax.swing.JDialog {
} else {
dialog.jEnableSounds.setSelected(false);
}
prop = prefs.get(KEY_MUSICS_ON, "true");
if (prop.equals("true")) {
dialog.jEnableMusics.setSelected(true);
} else {
dialog.jEnableMusics.setSelected(false);
}
}
private static void loadProxySettings(Preferences prefs) {
@ -1449,6 +1472,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
private javax.swing.JCheckBox displayBigCardsInHand;
private javax.swing.JButton exitButton;
private javax.swing.JTextField imageFolderPath;
private javax.swing.JCheckBox jEnableMusics;
private javax.swing.JCheckBox jEnableSounds;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;

View file

@ -2,6 +2,7 @@ package mage.client.util;
import java.io.File;
import java.awt.List;
import javax.sound.sampled.*;
import mage.client.constants.Constants;
/**
@ -16,15 +17,13 @@ public class MusicPlayer {
List filelist = new List();
static MusicPlayer player = null;
public static String BASE_BGM_PATH = "G:\\mp3\\东方\\TH13_-_东方神灵庙BGM\\";
public MusicPlayer(){
open();
}
//open file and add list
private void open(){
filepath = BASE_BGM_PATH;
filepath = Constants.BASE_MUSICS_PATH;
filelist.removeAll();
File filedir = new File(filepath);
File[] fileread = filedir.listFiles();
@ -122,7 +121,7 @@ public class MusicPlayer {
}
}
public void run(){
try {
Thread.sleep(100);