bd623697e0aea58ef3f4e724599371672d1d1719
[IRC.git] / Robust / src / Tests / ssJava / mp3decoder / MP3Player.java
1 // command line player for MPEG audio file
2 public class MP3Player {
3
4   private String filename = null;
5
6   public static void main(String args[]) {
7
8     MP3Player player = new MP3Player();
9     player.init(args);
10
11   }
12
13   private void init(String[] args) {
14     if (args.length == 1) {
15       filename = args[0];
16     }
17     play();
18   }
19
20   /**
21    * Playing file from FileInputStream.
22    */
23   protected InputStream getInputStream() throws IOException {
24     FileInputStream fin = new FileInputStream(filename);
25     BufferedInputStream bin = new BufferedInputStream(fin);
26     return bin;
27   }
28
29   public void play() throws JavaLayerException {
30     try {
31       System.out.println("playing " + filename + "...");
32       InputStream in = getInputStream();
33       AudioDevice dev = new AudioDevice();
34       Player player = new Player(in, dev);
35       player.play();
36     } catch (IOException ex) {
37       throw new JavaLayerException("Problem playing file " + filename, ex);
38     } 
39   }
40
41 }