~gryle-devel/gryle/trunk-deleted

« back to all changes in this revision

Viewing changes to src/javazoom/jl/player/advanced/jlap.java

  • Committer: Richard Leo Marsh Warburton
  • Date: 2007-01-13 22:08:02 UTC
  • mto: (1.1.6 gryle)
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: rlmw@viglab-28-20070113220802-6cjjur0hdk1rce47
added src files

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * 11/19/04             1.0 moved to LGPL. 
 
3
 *-----------------------------------------------------------------------
 
4
 *   This program is free software; you can redistribute it and/or modify
 
5
 *   it under the terms of the GNU Library General Public License as published
 
6
 *   by the Free Software Foundation; either version 2 of the License, or
 
7
 *   (at your option) any later version.
 
8
 *
 
9
 *   This program is distributed in the hope that it will be useful,
 
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 *   GNU Library General Public License for more details.
 
13
 *
 
14
 *   You should have received a copy of the GNU Library General Public
 
15
 *   License along with this program; if not, write to the Free Software
 
16
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
17
 *----------------------------------------------------------------------
 
18
 */
 
19
 
 
20
package javazoom.jl.player.advanced;
 
21
 
 
22
import java.io.BufferedInputStream;
 
23
import java.io.File;
 
24
import java.io.FileInputStream;
 
25
import java.io.IOException;
 
26
import java.io.InputStream;
 
27
 
 
28
import javazoom.jl.decoder.JavaLayerException;
 
29
 
 
30
/**
 
31
 * This class implements a sample player using Playback listener.
 
32
 */
 
33
public class jlap {
 
34
 
 
35
        public static void main(String[] args) {
 
36
                jlap test = new jlap();
 
37
                if (args.length != 1) {
 
38
                        test.showUsage();
 
39
                        System.exit(0);
 
40
                } else {
 
41
                        try {
 
42
                                test.play(args[0]);
 
43
                        } catch (Exception ex) {
 
44
                                System.err.println(ex.getMessage());
 
45
                                System.exit(0);
 
46
                        }
 
47
                }
 
48
        }
 
49
 
 
50
        public void play(String filename) throws JavaLayerException, IOException {
 
51
                InfoListener lst = new InfoListener();
 
52
                playMp3(new File(filename), lst);
 
53
        }
 
54
 
 
55
        public void showUsage() {
 
56
                System.out.println("Usage: jla <filename>");
 
57
                System.out.println("");
 
58
                System.out
 
59
                                .println(" e.g. : java javazoom.jl.player.advanced.jlap localfile.mp3");
 
60
        }
 
61
 
 
62
        public static AdvancedPlayer playMp3(File mp3, PlaybackListener listener)
 
63
                        throws IOException, JavaLayerException {
 
64
                return playMp3(mp3, 0, Integer.MAX_VALUE, listener);
 
65
        }
 
66
 
 
67
        public static AdvancedPlayer playMp3(File mp3, int start, int end,
 
68
                        PlaybackListener listener) throws IOException, JavaLayerException {
 
69
                return playMp3(new BufferedInputStream(new FileInputStream(mp3)),
 
70
                                start, end, listener);
 
71
        }
 
72
 
 
73
        public static AdvancedPlayer playMp3(final InputStream is, final int start,
 
74
                        final int end, PlaybackListener listener) throws JavaLayerException {
 
75
                final AdvancedPlayer player = new AdvancedPlayer(is);
 
76
                player.setPlayBackListener(listener);
 
77
                // run in new thread
 
78
                new Thread() {
 
79
                        public void run() {
 
80
                                try {
 
81
                                        player.play(start, end);
 
82
                                } catch (Exception e) {
 
83
                                        throw new RuntimeException(e.getMessage());
 
84
                                }
 
85
                        }
 
86
                }.start();
 
87
                return player;
 
88
        }
 
89
 
 
90
        public class InfoListener extends PlaybackListener {
 
91
                public void playbackStarted(PlaybackEvent evt) {
 
92
                        System.out.println("Play started from frame " + evt.getFrame());
 
93
                }
 
94
 
 
95
                public void playbackFinished(PlaybackEvent evt) {
 
96
                        System.out.println("Play completed at frame " + evt.getFrame());
 
97
                        System.exit(0);
 
98
                }
 
99
        }
 
100
}
 
 
b'\\ No newline at end of file'