📄 settings.java
字号:
no.auc.one.portableplayer.lmr.MediaRenderer.getInstance().udn());
ui.setCurrentMediaRenderer();
}
}
} catch (RecordStoreException rse) {
LOG.debug("RS Exception...");
rse.printStackTrace();
} catch (NullPointerException npe) {
System.err.println("Nullpointer occured: " + npe);
npe.printStackTrace();
if (settingsStore != null) {
try {
settingsStore.closeRecordStore();
} catch (RecordStoreException rse) {
System.err.println("Error closing record store.");
rse.printStackTrace();
} finally {
settingsStore = null;
}
}
try {
RecordStore.deleteRecordStore(SETTINGS_STORE_NAME);
settingsStore = RecordStore.openRecordStore(
SETTINGS_STORE_NAME,
true);
settingsStore.addRecord(null, 0, 0);
settingsStore.addRecord(null, 0, 0);
settingsStore.addRecord(null, 0, 0);
settingsStore.addRecord(null, 0, 0);
settingsStore.addRecord(null, 0, 0);
} catch (RecordStoreException rsnfe) {
System.err.println("Error deleting settings store.");
rsnfe.printStackTrace();
}
} finally {
System.err.println("Finished with loading settings. Now closing down...");
if (settingsStore != null) {
try {
LOG.debug("Closing record store");
settingsStore.closeRecordStore();
} catch (RecordStoreException e) {
System.err.println("Error while closing rec store: " + e);
e.printStackTrace();
}
}
System.err.println("Check loadMediaServerSetting...");
if (loadMediaServerSetting != null && loadMediaServerSetting.isAlive()) {
System.err.println(
"Must interrupt loadMediaServerSetting thread");
loadMediaServerSetting.interrupt();
}
System.err.println("Check loadMediaRendererSetting...");
if (loadMediaRendererSetting != null && loadMediaRendererSetting.isAlive()) {
System.err.println(
"Must interrupt loadMediaRendererSetting thread");
loadMediaRendererSetting.interrupt();
}
}
}
private final class LoadDeviceSetting extends Thread {
private int deviceType;
private String locationUrl;
private String UDN;
public LoadDeviceSetting(
int deviceType,
String locationUrl,
String UDN)
{
super();
System.err.println(
"LoadDeviceSetting ctor: deviceType=" + deviceType +
"; location URL=" + locationUrl + "; UDN=" + UDN);
this.deviceType = deviceType;
this.locationUrl = locationUrl;
this.UDN = UDN;
}
public void run() {
System.err.println("Starting to find device of type " + deviceType);
if (SETTING_MEDIASERVER == deviceType) {
try {
addMediaServerByLocationUrl(locationUrl);
} catch (Exception e) {
// Do nothing
}
if (!mediaServers.containsKey(UDN)) {
try {
addMediaServerByUDN(UDN);
} catch (Exception e) {
// Do nothing
}
}
} else if (SETTING_MEDIARENDERER == deviceType) {
try {
addMediaRendererByLocationUrl(locationUrl);
} catch (Exception e) {
// Do nothing
}
if (!mediaRenderers.containsKey(UDN)) {
try {
addMediaRendererByUDN(UDN);
} catch (Exception e) {
// Do nothing
}
}
}
}
}
private void saveUPnPDevice(int index, UPnPDevice dev) {
String s = dev.getFriendlyName();
LOG.debug("Saving UPnPDevice: " + s + " to RMS");
s = s + "|" + dev.getDeviceDescriptionLocation();
s = s + "|" + dev.getDeviceUDN();
// XXX
System.out.println("Saving UPnPDevice: " + s + " to RMS");
byte[] data = s.getBytes();
try {
settingsStore.setRecord(
index,
data,
0,
data.length);
}
catch (RecordStoreNotOpenException e) {
LOG.fatal("Could not save UPnPDevice to RMS");
}
catch (InvalidRecordIDException e) {
LOG.fatal("Invalid record ID exception");
}
catch (RecordStoreException e) {
LOG.fatal("Record store exception");
}
}
private void saveBooleanValue(int index, boolean value) {
String s = "";
if (value == true) {
s = "true";
}
else if (value == false) {
s = "false";
}
byte[] data = s.getBytes();
try {
settingsStore.setRecord(
index,
data,
0,
data.length);
}
catch (RecordStoreNotOpenException e) {
LOG.fatal("Record store not open exception");
}
catch (InvalidRecordIDException e) {
LOG.fatal("Invalid record ID exception");
}
catch (RecordStoreException e) {
LOG.fatal("Record store exception");
}
}
private void saveIntValue(int index, int value) {
String s = "" + value;
byte[] data = s.getBytes();
try {
settingsStore.setRecord(
index,
data,
0,
data.length);
}
catch (RecordStoreNotOpenException e) {
LOG.fatal("Record store not open exception");
}
catch (InvalidRecordIDException e) {
LOG.fatal("Invalid record ID exception");
}
catch (RecordStoreException e) {
LOG.fatal("Record store exception");
}
}
/**
* Used to save settings to RMS
*/
public void saveSettings() {
if(settingsChanged == true) {
System.out.println("Saving settings");
try {
settingsStore = RecordStore.openRecordStore("ONEPP-Settings", true);
LOG.debug("Saving settings to RMS...");
for (RecordEnumeration e =
settingsStore.enumerateRecords(null, null, false);
e.hasNextElement(); )
{
int recordId = e.nextRecordId();
LOG.debug("Record id = " + recordId);
switch(recordId) {
case SETTING_MEDIASERVER: {
if(currentMediaServer != null) {
saveUPnPDevice(
SETTING_MEDIASERVER,
(MediaServer)mediaServers.get(
currentMediaServer));
}
break;
}
case SETTING_MEDIARENDERER: {
if(currentMediaRenderer != null) {
saveUPnPDevice(
SETTING_MEDIARENDERER,
(MediaRenderer)mediaRenderers.get(
currentMediaRenderer));
}
break;
}
case SETTING_REPEAT: {
saveBooleanValue(SETTING_REPEAT, repeat);
break;
}
case SETTING_SHUFFLE: {
saveBooleanValue(SETTING_SHUFFLE, shuffle);
break;
}
case SETTING_HOSTINGPORT: {
saveIntValue(SETTING_HOSTINGPORT, hostingPort);
break;
}
}
}
// XXX save to RMS
settingsStore.closeRecordStore();
}
catch (RecordStoreException rse) {
LOG.debug("RS Exception...");
rse.printStackTrace();
}
}
}
/**
* Sets the current MediaRenderer to be used, based on the {@linkplain no.auc.one.portableplayer.librarymanager.LibraryMgr#renderers available renderers}.
*
* @param index The index to the AVRenderer element in the renderers Vector
* in the LibraryMgr which should be set as current renderer, SET TO -1 TO USE INTERNAL RENDERER.
*/
public void setCurrentMediaRendererUdn(String udn) {
if (udn == null || !mediaRenderers.containsKey(udn)) {
throw new IllegalArgumentException("Illegal UDN");
}
currentMediaRenderer = udn;
settingsChanged = true;
for(Enumeration e = settingsChangedListeners.elements();
e.hasMoreElements();)
{
((SettingsChanged)e.nextElement()).settingChanged(
SETTING_MEDIARENDERER,
getCurrentMediaRenderer());
}
}
/**
* Get the index of the current {@link no.auc.one.portableplayer.communication.mediarenderer.MediaRenderer MediaRenderer} in use.
*
* @return The index to the AVRenderer element in the renderers Vector in the
* LibraryMgr which is set as current renderer, IF -1, USE INTERNAL RENDERER
*/
public String currentMediaRendererUdn() {
return currentMediaRenderer;
}
public void updateMediaServerList() {
findMediaServers(null);
}
public void addMediaServerByLocationUrl(String locationUrl) {
synchronized(mediaServers) {
LOG.debug("Starting to find ms device description");
MediaServer ms = msf.getMediaServer(locationUrl);
if (ms != null) {
mediaServers.put(ms.getDeviceUDN(), ms);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -