All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.tidalwave.netbeans.soundplayer.impl.SoundPlayerImpl Maven / Gradle / Ivy

The newest version!
/***********************************************************************************************************************
 *
 * OpenBlueSky - NetBeans Platform Enhancements
 * Copyright (C) 2006-2012 by Tidalwave s.a.s. (http://www.tidalwave.it)
 *
 ***********************************************************************************************************************
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations under the License.
 *
 ***********************************************************************************************************************
 *
 * WWW: http://openbluesky.java.net
 * SCM: https://bitbucket.org/tidalwave/openbluesky-src
 *
 **********************************************************************************************************************/
package it.tidalwave.netbeans.soundplayer.impl;

import java.io.File;
import java.io.IOException;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import it.tidalwave.util.logging.Logger;
import it.tidalwave.netbeans.soundplayer.SoundPlayer;
import javax.annotation.Nonnull;
import org.openide.util.lookup.ServiceProvider;

/***********************************************************************************************************************
 *
 * @author  Fabrizio Giudici
 * @version $Id$
 *
 **********************************************************************************************************************/
@ServiceProvider(service=SoundPlayer.class)
public class SoundPlayerImpl implements SoundPlayer
  {
    private static final String CLASS = SoundPlayerImpl.class.getName();
    private static final Logger logger = Logger.getLogger(CLASS);
    
    /***************************************************************************
     * 
     * {@inheritDoc}
     *
     **************************************************************************/
    public void play (final @Nonnull DefaultSound sound)
      {
        logger.fine("play(%s)", sound);
        
        try 
          {
            final File sf = new File("/Users/fritz/Business/Tidalwave/Projects/blueMarine/blueMarine/trunk/src/blueMarine-core/Core/SoundPlayer/src/it/tidalwave/bluemarine/soundplayer/impl/sound/Note.mp3");
            final AudioFileFormat aff = AudioSystem.getAudioFileFormat(sf);
            final AudioInputStream ais = AudioSystem.getAudioInputStream(sf);
            final AudioFormat af = aff.getFormat();
            final DataLine.Info info = new DataLine.Info(Clip.class, ais.getFormat(), (int)ais.getFrameLength() * af.getFrameSize());
            final Clip ol = (Clip)AudioSystem.getLine(info);
            ol.open(ais);
            ol.loop(1);
            // TODO
          } 
        catch (LineUnavailableException e) 
          {
            logger.warning(CLASS, "play()", e.toString());
          }
        catch (UnsupportedAudioFileException e) 
          {
            logger.warning(CLASS, "play()", e.toString());
          }
        catch (IOException e) 
          {
            logger.warning(CLASS, "play()", e.toString());
          }
        catch (Exception e) // defensive
          {
            logger.warning(CLASS, "play()", e.toString());
          }
      }
  }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy