[309606] ScriptEditor
diff --git a/plugins/org.eclipse.actf.examples.scripteditor/src/org/eclipse/actf/ai/scripteditor/util/WavUtil.java b/plugins/org.eclipse.actf.examples.scripteditor/src/org/eclipse/actf/ai/scripteditor/util/WavUtil.java new file mode 100644 index 0000000..06a7d0e --- /dev/null +++ b/plugins/org.eclipse.actf.examples.scripteditor/src/org/eclipse/actf/ai/scripteditor/util/WavUtil.java
@@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2012 IBM Corporation and Others + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Kentarou FUKUDA - initial API and implementation + *******************************************************************************/ +package org.eclipse.actf.ai.scripteditor.util; + +import java.io.File; + +import javax.sound.sampled.AudioInputStream; +import javax.sound.sampled.AudioSystem; +import javax.sound.sampled.Clip; +import javax.sound.sampled.DataLine; + +public class WavUtil { + + /** + * @param file target WAV file + * @return length of WAV file in Microsecond + */ + public static long getMicrosecondLength(File file) { + long result = -1; + try { + AudioInputStream ais = AudioSystem.getAudioInputStream(file); + Clip clp = (Clip) AudioSystem.getLine(new DataLine.Info(Clip.class, + ais.getFormat())); + clp.open(ais); + result = clp.getMicrosecondLength(); + ais.close(); + } catch (Exception e) { + } + return result; + } + + /** + * @param file target WAV file + * @return length of WAV file in Millisecond + */ + public static double getMillisecondLength(File file) { + long result = getMicrosecondLength(file); + if (result == -1) { + return -1; + } + return result / (double)1000; + } + + /** + * @param file target WAV file + * @return length of WAV file in Second + */ + public static double getLength(File file) { + long result = getMicrosecondLength(file); + if (result == -1) { + return -1; + } + return result / (double)1000000; + } + +}
diff --git a/plugins/org.eclipse.actf.examples.scripteditor/src/org/eclipse/actf/examples/scripteditor/Activator.java b/plugins/org.eclipse.actf.examples.scripteditor/src/org/eclipse/actf/examples/scripteditor/Activator.java index e53a5fd..9a6d57c 100644 --- a/plugins/org.eclipse.actf.examples.scripteditor/src/org/eclipse/actf/examples/scripteditor/Activator.java +++ b/plugins/org.eclipse.actf.examples.scripteditor/src/org/eclipse/actf/examples/scripteditor/Activator.java
@@ -13,16 +13,16 @@ import java.util.MissingResourceException; import java.util.ResourceBundle; +import org.eclipse.actf.ui.util.AbstractUIPluginACTF; import org.eclipse.core.runtime.Platform; import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; /** * The activator class controls the plug-in life cycle */ -public class Activator extends AbstractUIPlugin { +public class Activator extends AbstractUIPluginACTF { // The plug-in ID public static final String PLUGIN_ID = "org.eclipse.actf.examples.scripteditor";