2
* 11/19/04 1.0 moved to LGPL.
4
* 06/04/01 Streaming support added. javalayer@javazoom.net
6
* 29/01/00 Initial version. mdm@techie.com
7
*-----------------------------------------------------------------------
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU Library General Public License as published
10
* by the Free Software Foundation; either version 2 of the License, or
11
* (at your option) any later version.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU Library General Public License for more details.
18
* You should have received a copy of the GNU Library General Public
19
* License along with this program; if not, write to the Free Software
20
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
*----------------------------------------------------------------------
24
package javazoom.jl.player;
26
import java.io.BufferedInputStream;
27
import java.io.FileInputStream;
28
import java.io.IOException;
29
import java.io.InputStream;
32
import javazoom.jl.decoder.JavaLayerException;
35
* The <code>jlp</code> class implements a simple command-line player for MPEG
38
* @author Mat McGowan (mdm@techie.com)
41
private String fFilename = null;
43
private boolean remote = false;
45
public static void main(String[] args) {
48
jlp player = createInstance(args);
51
} catch (Exception ex) {
52
System.err.println(ex);
53
ex.printStackTrace(System.err);
59
static public jlp createInstance(String[] args) {
60
jlp player = new jlp();
61
if (!player.parseArgs(args))
69
public jlp(String filename) {
73
protected void init(String filename) {
77
protected boolean parseArgs(String[] args) {
78
boolean parsed = false;
79
if (args.length == 1) {
83
} else if (args.length == 2) {
84
if (!(args[0].equals("-url"))) {
97
public void showUsage() {
98
System.out.println("Usage: jlp [-url] <filename>");
99
System.out.println("");
100
System.out.println(" e.g. : java javazoom.jl.player.jlp localfile.mp3");
102
.println(" java javazoom.jl.player.jlp -url http://www.server.com/remotefile.mp3");
104
.println(" java javazoom.jl.player.jlp -url http://www.shoutcastserver.com:8000");
107
public void play() throws JavaLayerException {
109
System.out.println("playing " + fFilename + "...");
110
InputStream in = null;
112
in = getURLInputStream();
114
in = getInputStream();
115
AudioDevice dev = getAudioDevice();
116
Player player = new Player(in, dev);
118
} catch (IOException ex) {
119
throw new JavaLayerException("Problem playing file " + fFilename,
121
} catch (Exception ex) {
122
throw new JavaLayerException("Problem playing file " + fFilename,
128
* Playing file from URL (Streaming).
130
protected InputStream getURLInputStream() throws Exception {
132
URL url = new URL(fFilename);
133
InputStream fin = url.openStream();
134
BufferedInputStream bin = new BufferedInputStream(fin);
139
* Playing file from FileInputStream.
141
protected InputStream getInputStream() throws IOException {
142
FileInputStream fin = new FileInputStream(fFilename);
143
BufferedInputStream bin = new BufferedInputStream(fin);
147
protected AudioDevice getAudioDevice() throws JavaLayerException {
148
return FactoryRegistry.systemRegistry().createAudioDevice();