diff options
author | geronimo <geronimo013@gmx.de> | 2012-07-26 16:32:37 +0200 |
---|---|---|
committer | geronimo <geronimo013@gmx.de> | 2012-07-26 16:32:37 +0200 |
commit | 55a02203e1d5fcdf8cbc0093af5c14d41d6d8dd7 (patch) | |
tree | 564507b5f40bcd65d7b6cb2d5041202c8250927f /cmpcj/src/de/schwarzrot/cmpc/app | |
parent | 2d0b837e6c885383ae807ca793cbe91aa32de995 (diff) | |
download | cmp-55a02203e1d5fcdf8cbc0093af5c14d41d6d8dd7.tar.gz cmp-55a02203e1d5fcdf8cbc0093af5c14d41d6d8dd7.tar.bz2 |
worked out little java client that serves to start other mediaplayers
Diffstat (limited to 'cmpcj/src/de/schwarzrot/cmpc/app')
-rw-r--r-- | cmpcj/src/de/schwarzrot/cmpc/app/ConfigFactory.java | 132 | ||||
-rw-r--r-- | cmpcj/src/de/schwarzrot/cmpc/app/IMediaPlayer.java | 46 | ||||
-rw-r--r-- | cmpcj/src/de/schwarzrot/cmpc/app/SRMediaPlayer.java | 181 |
3 files changed, 359 insertions, 0 deletions
diff --git a/cmpcj/src/de/schwarzrot/cmpc/app/ConfigFactory.java b/cmpcj/src/de/schwarzrot/cmpc/app/ConfigFactory.java new file mode 100644 index 0000000..f1c4685 --- /dev/null +++ b/cmpcj/src/de/schwarzrot/cmpc/app/ConfigFactory.java @@ -0,0 +1,132 @@ +/** + * ======================== legal notice ====================== + * + * File: ConfigFactory.java + * Created: + * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a> + * Project: cmpc - a java frontend (client) part of compound media player + * uses external players to play the media + * + * CMP - compound media player + * + * is a client/server mediaplayer intended to play any media from any workstation + * without the need to export or mount shares. cmps is an easy to use backend + * with a (ready to use) HTML-interface. Additionally the backend supports + * authentication via HTTP-digest authorization. + * cmpc is a client with vdr-like osd-menues. + * + * Copyright (c) 2012 Reinhard Mantey, some rights reserved! + * published under Creative Commons by-sa + * For details see http://creativecommons.org/licenses/by-sa/3.0/ + * + * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp + * + * -------------------------------------------------------------- + */ +package de.schwarzrot.cmpc.app; + + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import de.schwarzrot.cmpc.domain.Config; +import de.schwarzrot.cmpc.domain.Media; +import de.schwarzrot.cmpc.domain.MediaServer; +import de.schwarzrot.cmpc.domain.PlayerDefinition; + + +public class ConfigFactory { + protected static final Pattern SETUP_MASK = Pattern.compile("^\\s*(\\S+)\\s*=\\s*(.+)$"); + + + public ConfigFactory(File configDirectory) { + baseDir = configDirectory; + } + + + public Config getConfig() { + if (config == null) { + config = readConfig(); + } + return config; + } + + + protected Config readConfig() { + File setupFile = new File(baseDir, "srclient.conf"); + BufferedReader br = null; + Config rv = new Config(); + + if (setupFile.exists()) { + try { + br = new BufferedReader(new FileReader(setupFile)); + String line, trimmedLine; + + while ((line = br.readLine()) != null) { + trimmedLine = line.trim(); + + if (trimmedLine.isEmpty() || trimmedLine.startsWith("#")) + continue; + Matcher m = SETUP_MASK.matcher(trimmedLine); + + if (m.matches()) { + String key = m.group(1); + String value = m.group(2); + + if (key.compareToIgnoreCase("server") == 0) { + String[] parts = value.split("\\s*\\:\\s*"); + MediaServer ms = null; + + if (parts.length > 1) { + ms = new MediaServer(); + ms.setHostName(parts[0]); + ms.setPort(Integer.decode(parts[1])); + + rv.addServer(ms); + } + } else if (key.compareToIgnoreCase("player") == 0) { + String[] parts = value.split("\\s*\\:\\s*"); + PlayerDefinition pd = null; + + if (parts.length > 1) { + pd = new PlayerDefinition(); + String[] cmdline = parts[1].split("\\s+"); + + pd.setExecutable(cmdline[0]); + + for (int i = 1; i < cmdline.length; ++i) { + pd.addParameter(cmdline[i]); + } + if (parts[0].compareTo("*") == 0) { + // default player + for (Media.SupportedMediaType cmt : Media.SupportedMediaType.values()) + rv.putPlayer(cmt, pd); + } else { + for (Media.SupportedMediaType cmt : Media.SupportedMediaType.values()) { + if (parts[0].compareTo(cmt.name()) == 0) + rv.putPlayer(cmt, pd); + } + } + } + } + } + } + } catch (Throwable t) { + t.printStackTrace(); + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException e) { + } + } + } + } + return rv; + } + private Config config; + private File baseDir; +} diff --git a/cmpcj/src/de/schwarzrot/cmpc/app/IMediaPlayer.java b/cmpcj/src/de/schwarzrot/cmpc/app/IMediaPlayer.java new file mode 100644 index 0000000..d68adbc --- /dev/null +++ b/cmpcj/src/de/schwarzrot/cmpc/app/IMediaPlayer.java @@ -0,0 +1,46 @@ +/** + * ======================== legal notice ====================== + * + * File: IMediaPlayer.java + * Created: + * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a> + * Project: cmpc - a java frontend (client) part of compound media player + * uses external players to play the media + * + * CMP - compound media player + * + * is a client/server mediaplayer intended to play any media from any workstation + * without the need to export or mount shares. cmps is an easy to use backend + * with a (ready to use) HTML-interface. Additionally the backend supports + * authentication via HTTP-digest authorization. + * cmpc is a client with vdr-like osd-menues. + * + * Copyright (c) 2012 Reinhard Mantey, some rights reserved! + * published under Creative Commons by-sa + * For details see http://creativecommons.org/licenses/by-sa/3.0/ + * + * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp + * + * -------------------------------------------------------------- + */ +package de.schwarzrot.cmpc.app; + + +import de.schwarzrot.cmpc.domain.Config; + + +public interface IMediaPlayer { + public Config getConfig(); + + + public String getCurrentMediaCenter(); + + + public boolean isDebug(); + + + public void selectApp(); + + + public void startApp(String name, int port); +} diff --git a/cmpcj/src/de/schwarzrot/cmpc/app/SRMediaPlayer.java b/cmpcj/src/de/schwarzrot/cmpc/app/SRMediaPlayer.java new file mode 100644 index 0000000..73f6204 --- /dev/null +++ b/cmpcj/src/de/schwarzrot/cmpc/app/SRMediaPlayer.java @@ -0,0 +1,181 @@ +/** + * ======================== legal notice ====================== + * + * File: SRMediaPlayer.java + * Created: + * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a> + * Project: cmpc - a java frontend (client) part of compound media player + * uses external players to play the media + * + * CMP - compound media player + * + * is a client/server mediaplayer intended to play any media from any workstation + * without the need to export or mount shares. cmps is an easy to use backend + * with a (ready to use) HTML-interface. Additionally the backend supports + * authentication via HTTP-digest authorization. + * cmpc is a client with vdr-like osd-menues. + * + * Copyright (c) 2012 Reinhard Mantey, some rights reserved! + * published under Creative Commons by-sa + * For details see http://creativecommons.org/licenses/by-sa/3.0/ + * + * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp + * + * -------------------------------------------------------------- + */ +package de.schwarzrot.cmpc.app; + + +import java.awt.CardLayout; +import java.awt.Container; +import java.io.File; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.UIManager; +import javax.swing.UIManager.LookAndFeelInfo; +import de.schwarzrot.cmpc.domain.Config; +import de.schwarzrot.cmpc.ui.AppSelector; +import de.schwarzrot.cmpc.ui.MediaClient; + + +public class SRMediaPlayer implements IMediaPlayer { + private static final String DEFAULT_TITLE = "client"; + private static final String USER_HOME = "user.home"; + private static final String TITLE_MASK = "Compound Media Player (%s)"; + private static final String MAIN = "MediaServerSelector"; + private static final String CLIENT = "MediaClient"; + + + public SRMediaPlayer(String[] args, ConfigFactory cf) { + for (String a : args) { + if (a.compareTo("-d") == 0 || a.compareTo("--debug") == 0) + debug = true; + } + configFactory = cf; + } + + + public void createAndShowGUI() { + JFrame.setDefaultLookAndFeelDecorated(false); + + config = configFactory.getConfig(); + try { + for (LookAndFeelInfo lfi : UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(lfi.getName())) { + UIManager.setLookAndFeel(lfi.getClassName()); + JFrame.setDefaultLookAndFeelDecorated(true); + } + } + } catch (Throwable t) { + t.printStackTrace(); + System.exit(-1); + } + mainFrame = new JFrame("JMediaPlayer"); + + //Add components to it. + Container contentPane = mainFrame.getContentPane(); + setupMainView(contentPane); + + mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setTitle(DEFAULT_TITLE); + mainFrame.setSize(1000, 700); + mainFrame.setLocationRelativeTo(null); //center it + mainFrame.setVisible(true); + } + + + @Override + public Config getConfig() { + return config; + } + + + public ConfigFactory getConfigFactory() { + return configFactory; + } + + + @Override + public String getCurrentMediaCenter() { + return currentMediaCenter; + } + + + @Override + public boolean isDebug() { + return debug; + } + + + @Override + public void selectApp() { + setTitle(DEFAULT_TITLE); + switchView(MAIN); + } + + + public void setConfigFactory(ConfigFactory configFactory) { + this.configFactory = configFactory; + } + + + @Override + public void startApp(String name, int port) { + currentMediaCenter = name; + setTitle(name); + switchView(CLIENT); + try { + mediaClientPane.startConnection(name, port); + } catch (Throwable t) { + mediaClientPane.setActive(false); + switchView(MAIN); + } + } + + + protected void setTitle(String title) { + mainFrame.setTitle(String.format(TITLE_MASK, title)); + } + + + protected void setupMainView(Container clientArea) { + stakker = new CardLayout(); + switchingPane = new JPanel(stakker); + mediaClientPane = new MediaClient(CLIENT, this); + appSelectorPane = new AppSelector(MAIN, config.getKnownServers()); + + mediaClientPane.setup(this); + appSelectorPane.setup(this); + + switchingPane.add(appSelectorPane, MAIN); + switchingPane.add(mediaClientPane, CLIENT); + clientArea.add(switchingPane); + } + + + protected void switchView(String name) { + stakker.show(switchingPane, name); + } + + + public static void main(final String[] args) { + javax.swing.SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + File configDir = new File(System.getProperty(USER_HOME), ".cmp"); + SRMediaPlayer app = new SRMediaPlayer(args, new ConfigFactory(configDir)); + app.createAndShowGUI(); + } + }); + } + + private boolean debug = false; + private JFrame mainFrame; + private Config config; + private CardLayout stakker; + private JPanel switchingPane; + private MediaClient mediaClientPane; + private AppSelector appSelectorPane; + private ConfigFactory configFactory; + private String currentMediaCenter; +} |