View Javadoc

1   package com.melloware.jukes.gui.tool;
2   
3   import org.apache.commons.logging.Log;
4   import org.apache.commons.logging.LogFactory;
5   
6   import com.jgoodies.uif.application.Application;
7   import com.melloware.jukes.gui.view.MainFrame;
8   import com.melloware.jukes.util.MessageUtil;
9   
10  import javax.sound.sampled.SourceDataLine;
11  
12  import javazoom.jlgui.basicplayer.BasicPlayer;
13  import javazoom.jlgui.basicplayer.BasicPlayerEvent;
14  import javazoom.jlgui.basicplayer.BasicPlayerException;
15  
16  /**
17   * Override BasicPlayer to get to some protected methods.
18   * <p>
19   * Copyright (c) 1999-2007 Melloware, Inc. <http://www.melloware.com>
20   * @author Emil A. Lefkof III <info@melloware.com>
21   * @version 4.0
22   * AZ Development 2010
23   */
24  public final class JukesPlayer extends BasicPlayer {
25     /**
26      * Logger for this class
27      */
28     private static final Log LOG = LogFactory.getLog(JukesPlayer.class);
29  
30  	/* (non-Javadoc)
31      * @see javazoom.jlgui.basicplayer.BasicPlayer#run()
32      */
33     @Override
34     public void run() {
35        try {
36      	  // AZ: Set Initial Volume
37      	  if (super.hasGainControl()) {
38      		  super.setGain(MainModule.SETTINGS.getPlayerVolume());
39      	  } 
40           super.run();
41        } catch (RuntimeException ex) {
42      	  final String errorMessage = Resources.getString("messages.ErrorPlayFile");
43            LOG.error(errorMessage, ex);
44            final MainFrame mainFrame = (MainFrame) Application.getDefaultParentFrame();
45            MessageUtil.showError(mainFrame,errorMessage); 
46            notifyEvent(BasicPlayerEvent.STOPPED, getEncodedStreamPosition(), -1, null);
47        } catch (BasicPlayerException ex) {
48      	  final String errorMessage = Resources.getString("messages.ErrorPlayFile");
49            LOG.error(errorMessage, ex);
50            MessageUtil.showError(null,errorMessage+": "+ ex.getMessage()); 
51            notifyEvent(BasicPlayerEvent.STOPPED, getEncodedStreamPosition(), -1, null);
52  	}
53     }
54  
55     public SourceDataLine getSourceDataLine() {
56  		return this.m_line;
57  	}
58  }