|
@@ -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
|
}
|