1:
37:
38: package ;
39:
40: import ;
41:
42: import ;
43:
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53: import ;
54: import ;
55: import ;
56:
57:
63: public class GstAudioFileReader
64: extends AudioFileReader
65: {
66: @Override
67: public AudioFileFormat getAudioFileFormat(File file)
68: throws UnsupportedAudioFileException, IOException
69: {
70: CPStringBuilder name = new CPStringBuilder(file.getName());
71: String _name = name.substring(name.lastIndexOf(".") + 1);
72:
73: return getAudioFileFormat(
74: new BufferedInputStream(new FileInputStream(file)), _name);
75: }
76:
77: @Override
78: public AudioFileFormat getAudioFileFormat(InputStream is)
79: throws UnsupportedAudioFileException, IOException
80: {
81: return getAudioFileFormat(is, null);
82: }
83:
84: private AudioFileFormat getAudioFileFormat(InputStream is, String extension)
85: throws UnsupportedAudioFileException
86: {
87: AudioFormat format = null;
88: try
89: {
90: format = GstAudioFileReaderNativePeer.getAudioFormat(is);
91: }
92: catch (Exception e)
93: {
94: UnsupportedAudioFileException ex =
95: new UnsupportedAudioFileException("Unsupported encoding.");
96:
97: ex.initCause(ex.getCause());
98: throw ex;
99: }
100:
101: if (format == null)
102: throw new UnsupportedAudioFileException("Unsupported encoding.");
103:
104: String name = format.getProperty(GStreamerMixer.GST_DECODER).toString();
105:
106: if (extension == null)
107: {
108: extension =
109: format.getProperty(GStreamerMixer.GST_FILE_EXTENSION).toString();
110: }
111:
112: AudioFileFormat.Type type =
113: new AudioFileFormat.Type(name, extension);
114:
115:
116:
117: return new AudioFileFormat(type, format, AudioSystem.NOT_SPECIFIED);
118: }
119:
120: @Override
121: public AudioFileFormat getAudioFileFormat(URL url)
122: throws UnsupportedAudioFileException, IOException
123: {
124: return getAudioFileFormat(new BufferedInputStream(url.openStream()));
125: }
126:
127: @Override
128: public AudioInputStream getAudioInputStream(File file)
129: throws UnsupportedAudioFileException, IOException
130: {
131: InputStream stream = new FileInputStream(file);
132: long length = file.length();
133:
134: AudioFormat format = null;
135:
136: try
137: {
138: format = GstAudioFileReaderNativePeer.getAudioFormat(file);
139: }
140: catch (Exception e)
141: {
142: UnsupportedAudioFileException ex =
143: new UnsupportedAudioFileException("Unsupported encoding.");
144:
145: ex.initCause(ex.getCause());
146: throw ex;
147: }
148:
149:
150: if (format == null)
151: throw new UnsupportedAudioFileException("Unsupported encoding.");
152:
153: return new AudioInputStream(stream, format, length);
154: }
155:
156: @Override
157: public AudioInputStream getAudioInputStream(InputStream is)
158: throws UnsupportedAudioFileException, IOException
159: {
160: AudioFormat format = null;
161:
162: try
163: {
164: format = GstAudioFileReaderNativePeer.getAudioFormat(is);
165: }
166: catch (Exception e)
167: {
168:
169: e.printStackTrace();
170: }
171:
172:
173: if (format == null)
174: throw new UnsupportedAudioFileException("Unsupported encoding.");
175:
176: return new AudioInputStream(is, format, AudioSystem.NOT_SPECIFIED);
177: }
178:
179: @Override
180: public AudioInputStream getAudioInputStream(URL url)
181: throws UnsupportedAudioFileException, IOException
182: {
183: return getAudioInputStream(new BufferedInputStream(url.openStream()));
184: }
185: }