|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.examples.modules.minicomposer; import java.io.File; import java.io.IOException; import javax.sound.sampled.*; import org.openide.ErrorManager; import org.openide.execution.*; import org.openide.filesystems.*; import org.openide.util.*; public class InternalPlayer implements Player { public ExecutorTask play(String displayName, FileObject fo, ScoreCookie s) throws IOException { if (fo == null) { IOException ioe = new IOException("No .au: " + displayName); ErrorManager.getDefault().annotate(ioe, NbBundle.getMessage(InternalPlayer.class, "EXC_No_AU_file_found")); throw ioe; } final File f = FileUtil.toFile(fo); if (f == null) { IOException ioe = new IOException("No .au: " + displayName); ErrorManager.getDefault().annotate(ioe, NbBundle.getMessage(InternalPlayer.class, "EXC_file_must_be_local")); throw ioe; } class Job implements Runnable { public void run() { try { AudioInputStream ais = AudioSystem.getAudioInputStream(f); DataLine.Info dlinfo = new DataLine.Info(Clip.class, ais.getFormat()); Clip clip = (Clip)AudioSystem.getLine(dlinfo); clip.open(ais); clip.start(); try { while (clip.isActive()) { Thread.sleep(1000); } } catch (InterruptedException ie) { // ignore - job stopped } clip.stop(); clip.close(); } catch (Exception e) { // Will appear in Output Window. e.printStackTrace(); } } } return ExecutionEngine.getDefault().execute (NbBundle.getMessage(InternalPlayer.class, "LBL_audio_play_process"), new Job(), null); } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.