Skip to content
Browse files

fire StartStopListener events asynchronously

  • Loading branch information...
1 parent a5a19ef commit 30bd11b92dbbc3f1c92a9764b78b03b076164bc5 @chocolateboy chocolateboy committed Aug 13, 2011
Showing with 24 additions and 11 deletions.
  1. +24 −11 ps3mediaserver/net/pms/dlna/DLNAResource.java
View
35 ps3mediaserver/net/pms/dlna/DLNAResource.java
@@ -1155,33 +1155,39 @@ public void startPlaying(final String rendererId) {
if (refCount == 0) {
final DLNAResource self = this;
Runnable r = new Runnable() {
-
public void run() {
logger.trace("StartStopListener: event: start");
logger.trace("StartStopListener: renderer: " + rendererId);
logger.trace("StartStopListener: file: " + getSystemName());
- logger.trace("StartStopListener:");
- for (ExternalListener listener : ExternalFactory.getExternalListeners()) {
+
+ for (final ExternalListener listener : ExternalFactory.getExternalListeners()) {
if (listener instanceof StartStopListener) {
- ((StartStopListener) listener).nowPlaying(media, self);
+ // run these asynchronously for slow handlers (e.g. logging, scrobbling)
+ Runnable fireStartStopEvent = new Runnable() {
+ public void run() {
+ ((StartStopListener) listener).nowPlaying(media, self);
+ }
+ };
+ new Thread(fireStartStopEvent).start();
}
}
}
};
+
new Thread(r).start();
}
}
}
/**
- * Plugin implementation. When this item is going to play, it will notify all the StartStopListener objects available.
+ * Plugin implementation. When this item is going to stop playing, it will notify all the StartStopListener
+ * objects available.
* @see StartStopListener
*/
public void stopPlaying(final String rendererId) {
final DLNAResource self = this;
final String requestId = getRequestId(rendererId);
Runnable defer = new Runnable() {
-
public void run() {
try {
Thread.sleep(STOP_PLAYING_DELAY);
@@ -1196,25 +1202,32 @@ public void run() {
requestIdToRefcount.put(requestId, refCount - 1);
Runnable r = new Runnable() {
-
public void run() {
if (refCount == 1) {
logger.trace("StartStopListener: event: stop");
logger.trace("StartStopListener: renderer: " + rendererId);
logger.trace("StartStopListener: file: " + getSystemName());
- logger.trace("StartStopListener:");
- for (ExternalListener listener : ExternalFactory.getExternalListeners()) {
+
+ for (final ExternalListener listener : ExternalFactory.getExternalListeners()) {
if (listener instanceof StartStopListener) {
- ((StartStopListener) listener).donePlaying(media, self);
+ // run these asynchronously for slow handlers (e.g. logging, scrobbling)
+ Runnable fireStartStopEvent = new Runnable() {
+ public void run() {
+ ((StartStopListener) listener).donePlaying(media, self);
+ }
+ };
+ new Thread(fireStartStopEvent).start();
}
}
}
}
};
+
new Thread(r).start();
}
}
};
+
new Thread(defer).start();
}
@@ -1444,4 +1457,4 @@ public int getType() {
public boolean allowScan() {
return false;
}
-}
+}

0 comments on commit 30bd11b

Please sign in to comment.
Something went wrong with that request. Please try again.