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
18
19
20
21
22
23
24 public final class JukesPlayer extends BasicPlayer {
25
26
27
28 private static final Log LOG = LogFactory.getLog(JukesPlayer.class);
29
30
31
32
33 @Override
34 public void run() {
35 try {
36
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 }