1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.util.launcher;
21
22 import java.io.File;
23 import java.io.IOException;
24
25 import org.apache.log4j.Logger;
26 import org.xnap.XNap;
27
28 /***
29 * Provides player support for iTunes on Mac OS X through osascript calls.
30 */
31 public class ITunesPlayer extends DefaultPlayer
32 {
33
34
35
36
37 private static Logger logger = Logger.getLogger(ITunesPlayer.class);
38
39
40
41 public ITunesPlayer()
42 {
43 super("iTunes", XNap.tr("iTunes"), "");
44 }
45
46
47
48 public void enqueue(File file) throws IOException
49 {
50 String args[] = { "osascript", "-e",
51 "'tell application \"iTunes\" to run'",
52 "-e",
53 "'tell application \"iTunes\" to add {"
54 + "POSIX file \"" + file.getAbsolutePath()
55 + "\"}" };
56 Runtime.getRuntime().exec(args);
57 }
58
59 public void open(File file) throws IOException
60 {
61 String args[] = { "osascript", "-e",
62 "'tell application \"iTunes\" to run'",
63 "-e",
64 "'tell application \"iTunes\" to open {"
65 + "POSIX file \"" + file.getAbsolutePath()
66 + "\"}" };
67 Runtime.getRuntime().exec(args);
68 }
69
70
71 public boolean isEditable()
72 {
73 return false;
74 }
75
76 public void start() throws IOException
77 {
78 String args[] = { "osascript", "-e",
79 "'tell application \"iTunes\" to run'",
80 "-e",
81 "'tell application \"iTunes\" to playpause'" };
82 Runtime.getRuntime().exec(args);
83 }
84
85 public void stop()
86 {
87 String args[] = { "osascript", "-e",
88 "'tell application \"iTunes\" to stop'" };
89 try {
90 Runtime.getRuntime().exec(args);
91 }
92 catch (IOException ie) {
93 logger.debug("iTunes stop", ie);
94 }
95 }
96 }