*/
package mircoders.media;
-import java.io.StringReader;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Vector;
+import java.io.File;
+import java.io.FileOutputStream;
import mir.entity.Entity;
import mir.log.LoggerWrapper;
import mir.media.MediaExc;
import mir.media.MediaFailure;
import mir.media.MediaHandler;
-import mir.misc.FileUtil;
import mir.misc.StringUtil;
+import mir.util.IORoutines;
/**
* Please note: this media handler produces
*
* @see mir.media.MediaHandler
* @author mh <mh@nadir.org>
- * @version $Id: MediaHandlerMp3.java,v 1.17 2004/11/06 20:04:00 idfx Exp $
+ * @version $Id: MediaHandlerMp3.java,v 1.18 2007/04/08 21:46:35 idfx Exp $
*/
-public class MediaHandlerMp3 extends MediaHandlerAudio implements MediaHandler
-{
-
+public class MediaHandlerMp3 extends MediaHandlerAudio implements MediaHandler {
public MediaHandlerMp3() {
logger = new LoggerWrapper("Media.Audio.Mp3");
}
+ /**
+ * {@inheritDoc}
+ */
public void produce(Entity ent, Entity mediaTypeEnt) throws MediaExc, MediaFailure {
-
- // first check if the file exists
super.produce(ent, mediaTypeEnt);
String baseName = ent.getId();
String playlistFile = baseName + ".pls";
try {
- //write the "meta" files
- //first the .m3u since it only contains one line
- FileUtil.write(getStoragePath() + "/" + datePath + "/" + mpegURLFile,
- new StringReader(mp3Pointer), "US-ASCII");
- //now the .pls file
- FileUtil.write(getStoragePath() + "/" + datePath + "/" + playlistFile,
- new StringReader(mp3Pointer), "US-ASCII");
+ IORoutines.writeStream(mp3Pointer, "us-ascii",
+ new FileOutputStream(new File(getBaseStoragePath() + "/" + datePath + "/" + mpegURLFile)));
+
+ IORoutines.writeStream(mp3Pointer, "us-ascii",
+ new FileOutputStream(new File(getBaseStoragePath() + "/" + datePath + "/" + playlistFile)));
+ reportChange(getBaseStoragePath() + "/" + datePath + "/" + mpegURLFile);
+ reportChange(getBaseStoragePath() + "/" + datePath + "/" + playlistFile);
}
catch (Throwable e) {
- logger.error("MediaHandlerMp3.produce: " + e.toString());
+ logger.error("MediaHandlerMp3.execute: " + e.toString());
throw new MediaFailure(e);
}
}
-
- public List getURL(Entity ent, Entity mediaTypeEnt) {
- List theList = new Vector();
-
- //String stringSize = ent.getFieldValue("size");
- //int size = Integer.parseInt(stringSize, 10)/1024;
- theList.add(ent);
-
- String basePath = StringUtil.regexpReplace(ent.getFieldValue("publish_path"),
- ".mp3$", "");
-
- // @todo the texts ("title") below urgently need to be sanely localizaeble
- // somehow
- Map m3uHash = new HashMap();
- m3uHash.put("publish_path", basePath + ".m3u");
- m3uHash.put("publish_server", ent.getFieldValue("publish_server"));
- m3uHash.put("title", "stream URL");
- theList.add(m3uHash);
-
- Map plsHash = new HashMap();
- plsHash.put("publish_path", basePath + ".pls");
- plsHash.put("publish_server", ent.getFieldValue("publish_server"));
- plsHash.put("title", "playlist URL");
- theList.add(plsHash);
-
- return theList;
-
- }
-
+
public String getDescr(Entity mediaType) {
return "mp3";
}