Browse Source

Better handling of MPRIS failures

Fixes issue 3102

Change-Id: I5d41eddc174a63db1bd301f1cb757d21ef840126
Reviewed-on: http://gerrit.dmdirc.com/386
Reviewed-by: Gregory Holmes <greboid@dmdirc.com>
Tested-by: Gregory Holmes <greboid@dmdirc.com>
tags/0.6.3
Chris Smith 14 years ago
parent
commit
5ba42b21fc

+ 11
- 5
src/com/dmdirc/addons/mediasource_dbus/DBusMediaSource.java View File

79
     @Override
79
     @Override
80
     public List<MediaSource> getSources() {
80
     public List<MediaSource> getSources() {
81
         for (String mpris : doDBusCall("org.mpris.*", "/", "/")) {
81
         for (String mpris : doDBusCall("org.mpris.*", "/", "/")) {
82
-            final String service = mpris.substring(10);
83
-
84
-            if (!mprisSources.containsKey(service)) {
85
-                mprisSources.put(service, new MPRISSource(this, service));
86
-                sources.add(mprisSources.get(service));
82
+            try {
83
+                final String service = mpris.substring(10);
84
+
85
+                if (!mprisSources.containsKey(service)) {
86
+                    mprisSources.put(service, new MPRISSource(this, service));
87
+                    sources.add(mprisSources.get(service));
88
+                }
89
+            } catch (IllegalArgumentException ex) {
90
+                // The service either stopped after the initial call and before
91
+                // we created an MRPIS Source, or otherwise doesn't correctly
92
+                // implement MPRIS. Either way, ignore it.
87
             }
93
             }
88
         }
94
         }
89
 
95
 

+ 8
- 2
src/com/dmdirc/addons/mediasource_dbus/MPRISSource.java View File

54
         this.source = source;
54
         this.source = source;
55
         this.service = service;
55
         this.service = service;
56
 
56
 
57
-        this.name = source.doDBusCall("org.mpris." + service, "/",
58
-                "org.freedesktop.MediaPlayer.Identity").get(0).replace(' ', '_');
57
+        final List<String> info = source.doDBusCall("org.mpris." + service, "/",
58
+                "org.freedesktop.MediaPlayer.Identity");
59
+
60
+        if (info.isEmpty()) {
61
+            throw new IllegalArgumentException("No service with that name found");
62
+        }
63
+
64
+        this.name = info.get(0).replace(' ', '_');
59
     }
65
     }
60
 
66
 
61
     /** {@inheritDoc} */
67
     /** {@inheritDoc} */

Loading…
Cancel
Save