01: package org.millstone.examples.stoneplayer;
02:
03: import java.io.File;
04: import java.io.InputStream;
05: import java.io.FileInputStream;
06: import java.io.BufferedInputStream;
07:
08: /** StonePlayer song
09: *
10: * @author IT Mill Ltd
11: */
12: public class Song {
13:
14: File file;
15:
16: /** Name of the song. */
17: private String name;
18:
19: /** Artist of the song. */
20: private String artist;
21:
22: /** Creates a new instance of Song */
23: public Song(File file) {
24: this .file = file;
25:
26: if (file != null) {
27:
28: // We should use ID3 here
29: name = file.getName();
30: artist = file.getParent();
31: }
32: }
33:
34: /** Get the name of the song.
35: * @return Name of the song.
36: */
37: public String getName() {
38: return this .name;
39: }
40:
41: /** Get the name of the artist.
42: * @return Name of the artist.
43: */
44: public String getArtist() {
45: return this .artist;
46: }
47:
48: /** Get the name of the song.
49: * @return Name of the song.
50: */
51: public String toString() {
52: return getName();
53: }
54:
55: /** Get the input stream from which this song can be read. */
56: public InputStream getStream() {
57: try {
58: return new BufferedInputStream(new FileInputStream(file));
59: } catch (java.io.FileNotFoundException e) {
60: }
61: return null;
62: }
63:
64: /** Get the file for this song. */
65: public File getFile() {
66: return this .file;
67: }
68: }
69:
70: /* This Millstone sample code is public domain. *
71: * For more information see www.millstone.org. */
|