View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
10   *  This program is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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  	//--- Constant(s) ---
34  
35  	//--- Data field(s) ---
36  
37      private static Logger logger = Logger.getLogger(ITunesPlayer.class);
38  	
39  	//--- Constructor(s) ---
40  
41      public ITunesPlayer()
42  	{
43  		super("iTunes", XNap.tr("iTunes"), "");
44  	}
45  
46      //--- Method(s) ---
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  }