Quellcode durchsuchen

DI the Windows Media Source Plugin.

pull/302/head
Greg Holmes vor 9 Jahren
Ursprung
Commit
d2eb88bdbc

+ 3
- 3
mediasource_windows/src/com/dmdirc/addons/mediasource_windows/DllSource.java Datei anzeigen

@@ -36,7 +36,7 @@ public class DllSource implements MediaSource {
36 36
     /** Use getArtistTitle */
37 37
     private final boolean useArtistTitle;
38 38
     /** Parent Plugin. */
39
-    final WindowsMediaSourcePlugin parent;
39
+    final WindowsMediaSourceManager parent;
40 40
 
41 41
     /**
42 42
      * Instantiates the media source.
@@ -44,7 +44,7 @@ public class DllSource implements MediaSource {
44 44
      * @param parent     The plugin that owns this DllSource
45 45
      * @param playerName Name of Player and DLL
46 46
      */
47
-    public DllSource(final WindowsMediaSourcePlugin parent, final String playerName) {
47
+    public DllSource(final WindowsMediaSourceManager parent, final String playerName) {
48 48
         this(parent, playerName, false);
49 49
     }
50 50
 
@@ -56,7 +56,7 @@ public class DllSource implements MediaSource {
56 56
      * @param useArtistTitle True if getArtistTitle should be parsed rather than using getArtist()
57 57
      *                       and getTitle()
58 58
      */
59
-    public DllSource(final WindowsMediaSourcePlugin parent, final String playerName,
59
+    public DllSource(final WindowsMediaSourceManager parent, final String playerName,
60 60
             final boolean useArtistTitle) {
61 61
         this.playerName = playerName;
62 62
         this.useArtistTitle = useArtistTitle;

+ 8
- 68
mediasource_windows/src/com/dmdirc/addons/mediasource_windows/WindowsMediaSourcePlugin.java Datei anzeigen

@@ -22,89 +22,29 @@
22 22
 
23 23
 package com.dmdirc.addons.mediasource_windows;
24 24
 
25
-import com.dmdirc.addons.nowplaying.MediaSource;
26
-import com.dmdirc.addons.nowplaying.MediaSourceManager;
27 25
 import com.dmdirc.plugins.PluginInfo;
28
-import com.dmdirc.plugins.PluginManager;
29 26
 import com.dmdirc.plugins.implementations.BasePlugin;
30
-import com.dmdirc.plugins.implementations.PluginFilesHelper;
31
-import com.dmdirc.util.io.StreamUtils;
32 27
 
33
-import com.google.common.io.CharStreams;
34
-
35
-import java.io.IOException;
36
-import java.io.InputStreamReader;
37
-import java.util.ArrayList;
38
-import java.util.List;
28
+import dagger.ObjectGraph;
39 29
 
40 30
 /**
41 31
  * Manages all Windows based media sources.
42 32
  */
43
-public class WindowsMediaSourcePlugin extends BasePlugin
44
-        implements MediaSourceManager {
45
-
46
-    /** Media sources. */
47
-    private final List<MediaSource> sources;
48
-    /** Plugin files helper. */
49
-    private final PluginFilesHelper filesHelper;
33
+public class WindowsMediaSourcePlugin extends BasePlugin {
50 34
 
51
-    /**
52
-     * Creates a new instance of DcopMediaSourcePlugin.
53
-     *
54
-     * @param pluginInfo This plugin's plugin info
55
-     */
56
-    public WindowsMediaSourcePlugin(final PluginManager pluginManager,
57
-            final PluginInfo pluginInfo) {
58
-        this.filesHelper = new PluginFilesHelper(pluginManager, pluginInfo);
59
-        sources = new ArrayList<>();
60
-        sources.add(new DllSource(this, "Winamp", true));
61
-        sources.add(new DllSource(this, "iTunes", false));
62
-    }
35
+    private WindowsMediaSourceManager manager;
63 36
 
64 37
     @Override
65
-    public List<MediaSource> getSources() {
66
-        return sources;
67
-    }
68
-
69
-    /**
70
-     * Get the output from GetMediaInfo.exe for the given player and method
71
-     *
72
-     * @param player Player to ask about
73
-     * @param method Method to call
74
-     *
75
-     * @return a MediaInfoOutput with the results
76
-     */
77
-    protected MediaInfoOutput getOutput(final String player, final String method) {
78
-        try {
79
-            final Process myProcess = Runtime.getRuntime().exec(new String[]{
80
-                filesHelper.getFilesDirString() + "GetMediaInfo.exe",
81
-                player,
82
-                method});
83
-            StreamUtils.readStream(myProcess.getErrorStream());
84
-            final String data = CharStreams.toString(new InputStreamReader(
85
-                    myProcess.getInputStream()));
86
-            try {
87
-                myProcess.waitFor();
88
-            } catch (InterruptedException e) {
89
-            }
90
-
91
-            return new MediaInfoOutput(myProcess.exitValue(), data);
92
-        } catch (SecurityException | IOException e) {
93
-        }
38
+    public void load(final PluginInfo pluginInfo, final ObjectGraph graph) {
39
+        super.load(pluginInfo, graph);
94 40
 
95
-        return new MediaInfoOutput(-1, "Error executing GetMediaInfo.exe");
41
+        setObjectGraph(graph.plus(new WindowsMediaSourceModule(pluginInfo)));
42
+        manager = getObjectGraph().get(WindowsMediaSourceManager.class);
96 43
     }
97 44
 
98 45
     @Override
99 46
     public void onLoad() {
100
-        // Extract the .dlls and .exe
101
-        try {
102
-            filesHelper.extractResourcesEndingWith(".dll");
103
-            filesHelper.extractResourcesEndingWith(".exe");
104
-        } catch (IOException ex) {
105
-            throw new IllegalStateException("Unable to extract needed files: " + ex.getMessage(),
106
-                    ex);
107
-        }
47
+        manager.onLoad();
108 48
     }
109 49
 
110 50
 }

Laden…
Abbrechen
Speichern