[libbluray-devel] Implement HSound

hpi1 git at videolan.org
Tue May 7 08:22:06 CEST 2013


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Sat May  4 22:21:35 2013 +0300| [c0e277e6839ce99534855206dcb97975564d5044] | committer: hpi1

Implement HSound

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=c0e277e6839ce99534855206dcb97975564d5044
---

 src/libbluray/bdj/java/org/havi/ui/HSound.java     |   69 +++++++++++++++++---
 .../videolan/media/protocol/file/DataSource.java   |   60 +++++++++++++++++
 2 files changed, 120 insertions(+), 9 deletions(-)

diff --git a/src/libbluray/bdj/java/org/havi/ui/HSound.java b/src/libbluray/bdj/java/org/havi/ui/HSound.java
index 19ba00d..5681766 100644
--- a/src/libbluray/bdj/java/org/havi/ui/HSound.java
+++ b/src/libbluray/bdj/java/org/havi/ui/HSound.java
@@ -1,6 +1,7 @@
 /*
  * This file is part of libbluray
  * Copyright (C) 2010  William Hahne
+ * Copyright (C) 2013  Petri Hintukainen <phintuka at users.sourceforge.net>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -22,21 +23,38 @@ package org.havi.ui;
 import java.io.IOException;
 import java.net.URL;
 
+import javax.media.ControllerEvent;
+import javax.media.ControllerListener;
+import javax.media.EndOfMediaEvent;
+import javax.media.Manager;
+import javax.media.NoPlayerException;
+import javax.media.Player;
+import javax.media.Time;
+
 import org.videolan.Logger;
 
 public class HSound {
+    boolean isLooping = false;
+    Player player = null;
+    ControllerListenerImpl listener;
+
     public HSound() {
-        logger.unimplemented("HSound");
+        listener = new ControllerListenerImpl();
     }
 
     public void load(String location) throws IOException, SecurityException {
-        logger.unimplemented("load");
-        logger.info("load("+location+")");
+        load(new URL("file:" + location));
     }
 
     public void load(URL contents) throws IOException, SecurityException {
-        logger.unimplemented("load");
-        logger.info("load("+contents+")");
+        dispose();
+        try {
+            player = Manager.createPlayer(contents);
+        } catch (NoPlayerException e) {
+            IOException ioe = new IOException();
+            ioe.initCause(e);
+            throw ioe;
+        }
     }
 
     public void set(byte data[]) {
@@ -44,19 +62,52 @@ public class HSound {
     }
 
     public void play() {
-        logger.unimplemented("play");
+        if (player != null) {
+            isLooping = false;
+            player.addControllerListener(listener);
+            player.start();
+        }
     }
 
     public void stop() {
-        logger.unimplemented("stop");
+        if (player != null) {
+            player.removeControllerListener(listener);
+            player.stop();
+        }
     }
 
     public void loop() {
-        //logger.unimplemented("loop");
+        if (player != null) {
+            isLooping = true;
+            player.removeControllerListener(listener);
+            player.start();
+        }
     }
 
     public void dispose() {
-        //logger.unimplemented("dispose");
+        if (player != null) {
+            player.removeControllerListener(listener);
+            player.stop();
+            player.close();
+            player = null;
+        }
+    }
+
+
+    private class ControllerListenerImpl implements ControllerListener {
+        private ControllerListenerImpl() {
+        }
+
+        public void controllerUpdate(ControllerEvent event) {
+            if (event instanceof EndOfMediaEvent) {
+                if (isLooping) {
+                    player.setMediaTime(new Time(0L));
+                    player.start();
+                } else {
+                    stop();
+                }
+            }
+        }
     }
 
     private static final Logger logger = Logger.getLogger(HSound.class.getName());
diff --git a/src/libbluray/bdj/java/org/videolan/media/protocol/file/DataSource.java b/src/libbluray/bdj/java/org/videolan/media/protocol/file/DataSource.java
new file mode 100644
index 0000000..bb00bb2
--- /dev/null
+++ b/src/libbluray/bdj/java/org/videolan/media/protocol/file/DataSource.java
@@ -0,0 +1,60 @@
+/*
+ * This file is part of libbluray
+ * Copyright (C) 2013  Petri Hintukainen <phintuka at users.sourceforge.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+package org.videolan.media.protocol.file;
+
+import java.io.IOException;
+import javax.media.Time;
+
+public class DataSource extends javax.media.protocol.DataSource {
+    public Object[] getControls() {
+        return new Object[0];
+    }
+
+    public Object getControl(String controlType) {
+        return null;
+    }
+
+    public Time getDuration() {
+        org.videolan.Logger.unimplemented(DataSource.class.getName(), "getDuration");
+        return null;
+    }
+
+    public String getContentType() {
+        return contentType;
+    }
+
+    public void connect() throws IOException {
+        contentType = "audio";
+    }
+
+    public void disconnect() {
+        contentType = "unknown";
+    }
+
+    public void start() throws IOException {
+        if (contentType.equals("unknown"))
+            throw new IOException("Unknown content type.");
+    }
+
+    public void stop() throws IOException {
+    }
+
+    private String contentType = "unknown";
+}



More information about the libbluray-devel mailing list