मेरी पिछली पोस्ट में, मुझे एमपी 3 फ़ाइल पढ़ने की कोशिश करने में थोड़ी परेशानी थी। अब मैं ऐसा करने में सक्षम हूं और मैं जावा स्विंग के साथ एमपी 3 से डेटा प्रस्तुत करने में सक्षम होना चाहता हूं। और एमपी 3 खेलना और एक ही समय में कल्पना करना अच्छा लगेगा।विज़ुअलाइज़ेशन के लिए एमपी 3 बाइनरी डेटा पढ़ें
मेरे पास बाइनरी डेटा है (जिसे मैंने आउटपुटस्ट्रीम पर पाइप किया है) लेकिन मुझे नहीं पता कि डेटा की व्याख्या कैसे करें।
अनिवार्य रूप से, लगभग LINE57 के आसपास, मुझे बाइट सरणी के साथ क्या करने की आवश्यकता है ताकि मैं डेटा को डीबी मानों के रूप में समझ सकूं?
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.SourceDataLine;
public class MainSound {
public static void main(final String [] args) throws Exception {
System.out.println("Running");
System.out.println(System.getProperty("java.version"));
final AudioFileFormat.Type [] types = AudioSystem.getAudioFileTypes();
for (final AudioFileFormat.Type t : types) {
System.out.println("Returning Type : " + t);
} // End of the for //
final String PATH = "C:\\Users\\bbrown\\Downloads\\swing-hacks-examples-20060109\\Ch10-Audio\\75\\soundcloud2.mp3";
final File file = new File(PATH);
final AudioInputStream in = AudioSystem.getAudioInputStream(new BufferedInputStream(new FileInputStream(file)));
AudioInputStream din = null;
final AudioFormat baseFormat = in.getFormat();
final AudioFormat decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
baseFormat.getSampleRate(),
16,
baseFormat.getChannels(),
baseFormat.getChannels() * 2,
baseFormat.getSampleRate(),
false);
System.out.println("Channels : " + baseFormat.getChannels());
din = AudioSystem.getAudioInputStream(decodedFormat, in);
rawplay(decodedFormat, din);
in.close();
System.out.println("Done");
}
private static synchronized void rawplay(final AudioFormat targetFormat, final AudioInputStream din) throws IOException, LineUnavailableException {
final byte[] data = new byte[4096];
final SourceDataLine line = getLine(targetFormat);
if (line != null) {
System.out.println("Entering ...");
// Start
line.start();
int nBytesRead = 0, nBytesWritten = 0;
while (nBytesRead != -1) {
nBytesRead = din.read(data, 0, data.length);
if (nBytesRead != -1) {
// LINE57, HOW CAN INTERPRET this data for VISUALIZATION.
nBytesWritten = line.write(data, 0, nBytesRead);
System.out.println("... -->" + data[0] + " bytesWritten:" + nBytesWritten);
}
} // End of while //
System.out.println("Done ...");
// Stop
line.drain();
line.stop();
line.close();
din.close();
} // End of the if //
}
private static synchronized SourceDataLine getLine(AudioFormat audioFormat) throws LineUnavailableException {
SourceDataLine res = null;
final DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat);
res = (SourceDataLine) AudioSystem.getLine(info);
res.open(audioFormat);
return res;
}
} // End of the class //
उत्तर के लिए +1 वास्तव में मदद करता है अच्छा – MadProgrammer
@MadProgrammer +1 धन्यवाद, मैं अपने स्वयं के मीडियाप्लेयर को कोड करना चाहता हूं, इसलिए मुझे प्रतिस्पर्धियों पर एक चुस्त चोटी थी;) –
अच्छा उदाहरण, पठनीय कोड और वास्तव में मुझे क्या चाहिए। एमपी 3 प्लेयर के साथ अभी भी थोड़ी परेशानी थी। मुझे एक एमपी 3 प्लगइन (बाहरी) शामिल करना था। –