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.
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.
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
*----------------------------------------------------------------------
20
package javazoom.jl.player.advanced;
22
import java.io.BufferedInputStream;
24
import java.io.FileInputStream;
25
import java.io.IOException;
26
import java.io.InputStream;
28
import javazoom.jl.decoder.JavaLayerException;
31
* This class implements a sample player using Playback listener.
35
public static void main(String[] args) {
36
jlap test = new jlap();
37
if (args.length != 1) {
43
} catch (Exception ex) {
44
System.err.println(ex.getMessage());
50
public void play(String filename) throws JavaLayerException, IOException {
51
InfoListener lst = new InfoListener();
52
playMp3(new File(filename), lst);
55
public void showUsage() {
56
System.out.println("Usage: jla <filename>");
57
System.out.println("");
59
.println(" e.g. : java javazoom.jl.player.advanced.jlap localfile.mp3");
62
public static AdvancedPlayer playMp3(File mp3, PlaybackListener listener)
63
throws IOException, JavaLayerException {
64
return playMp3(mp3, 0, Integer.MAX_VALUE, listener);
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);
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);
81
player.play(start, end);
82
} catch (Exception e) {
83
throw new RuntimeException(e.getMessage());
90
public class InfoListener extends PlaybackListener {
91
public void playbackStarted(PlaybackEvent evt) {
92
System.out.println("Play started from frame " + evt.getFrame());
95
public void playbackFinished(PlaybackEvent evt) {
96
System.out.println("Play completed at frame " + evt.getFrame());
b'\\ No newline at end of file'