Hye there. I just want to play an mp3 file in my Java J2SE Desktop app. all is going fine with no exceptions but the problem is the audio sound is not heard I have checked my speakers as well use all kind a Java mp3 plugins like JMF and JLayer by JavaZoom. My code is listed below and i have added Jlayer.jar to my project also. Please help me give me solution of the problem because I'm trying since last 3 days but failed to do so! Please help me thanks in advance...
private void playMe(){
try{
String file="E://Net Beans Work Space//mp3//a.mp3";
FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis);
player = new Player(bis);
}catch(Exception e){
System.out.print("ERROR "+e);
}
}
Did you try to start the player?
player.start();
Related
This is my code
public static void main(String[] args) {
try{
// open the sound file as a Java input stream
InputStream in = new FileInputStream("Sound.wav");
// create an audiostream from the inputstream
AudioStream audioStream = new AudioStream(in);
// play the audio clip with the audioplayer class
AudioPlayer.player.start(audioStream);
}
catch(Exception e){
System.out.println("Audio not found");
}
}
Sun Audio is Undocumented
You should not be using Sun Audio in your program. See here and here.
The Answer Depends on Your Library
If you are using Java Clip (built-in), try the example here. This is probably the simplest method.
If you switch to use JavaFX, you can see the API here, which has ways to loop. However, JavaFX requires a bit of package restructuring, and there is a learning curve. Unless you need JavaFX for other reasons, I would avoid it.
If you are using any other library, please consult the API for that library, or share with us what you are attempting to use. I have personally used BasicPlayer, but it is quite old.
I wrote a media player, that I exported as a jar file.
It works great on my linux system. Compiled with 1.8, but to work with 1.6 as well.
Now my friend who needs to use it runs the jar on her mac (java 1.6) and the program works, does not throw an exception, but does not play sound.
Any ideas what could have gone wrong?
public void mediaPlayer()
throws Exception {
// open the sound file as a Java input stream
String soundFile = "./data/1.wav";
InputStream in = new FileInputStream(soundFile);
//
// // create an audiostream from the inputstream
AudioStream audioStream = new AudioStream(in);
// // play the audio clip with the audioplayer class
AudioPlayer.player.start(audioStream);
}
Oh, the data folder was misplaced. Solved.
I am trying to program a classroom assistant (I work as a teacher) using Java who will give spoken instructions to students/ask them questions etc. I have managed to connect successfully to the cerevoice cloud to create an ogg file
e.g. "https://cerevoice.s3.amazonaws.com/Heather220501c8c2e94d4650f64f7d951bf76b08b0eb.ogg"
however when I try to play this ogg file from java I get an error that it could not be found or that it is an unsupported audio resource depending on the ogg player I use (i have tried EasyOGG and TinySound so far) - both the ogg players work successfully locally but I cannot get them to play a file directly from the website.
Examples how I have tried to reference it:
URL url = new URL("https://cerevoice.s3.amazonaws.com/Heather220501c8c2e94d4650f64f7d951bf76b08b0eb.ogg");
Music song = TinySound.loadMusic(url);
song.play(true);
OggClip ogg = new OggClip("https://cerevoice.s3.amazonaws.com/Heather220501c8c2e94d4650f64f7d951bf76b08b0eb.ogg");
ogg.loop();
Apologies for my ignorance I'd really appreciate any help anyone can give with playing this file! =)
Many thanks,
Darren
Edited to show using a literal String value to help clarity
Edit very ugly hack 1 solution: //opens a browser window plays file then closes window
String url = "https://cerevoice.s3.amazonaws.com/Heather220501c8c2e94d4650f64f7d951bf76b08b0eb.ogg"; //hard coded here for simplicity but URL dynamically retrieved from webservice
java.awt.Desktop.getDesktop().browse(java.net.URI.create(url));
Thread.sleep(3000);
Runtime.getRuntime().exec("taskkill /F /IM chrome.exe");
Edit slightly less ugly hack 2 solution:
//creation of a temporary file to allow playing from java without creating a browser window
try{
Files.deleteIfExists(Paths.get("C:/cere/temp.ogg"));
try (InputStream in = URI.create(url.value).toURL().openStream()) {
Files.copy(in, Paths.get("C:/cere/temp.ogg"));
}catch(IOException e) {
}
I need to streaming media and video from samba server to android, and I use JCIFS to get inputstream from samba file.
But in MediaPlayer only can use fileinputstream.getFD() to play media.
mp = new MediaPlayer();
FileInputStream fis = new FileInputStream(convertedFile);
mp.setDataSource(fis.getFD());
Toast.makeText(this, "Success, Path has been set", Toast.LENGTH_SHORT).show();
mp.prepare();
mp.start();
I can't getFD() from inputstream so that I need to convert inputstream to fileinputstream...
Please give me a suggest, or there hava others solution to streaming media from samba server ?
This is my SmbFileInputStream, but it's not equals than fileinputstream
SmbFileInputStream f = new SmbFileInputStream(new SmbFile(filePath,auth));
Thanks a lot.
You can create a ParcelFileDescriptor pipe using createPipe(). You would copy bytes from your FileInputStream into an OutputStream on your end of the pipe, and give the FileDescriptor from getFileDescriptor() to MediaPlayer. Whether this will work or not with your desired stream is a completely different matter, but it's the only way I know of to get a FileDescriptor that represents arbitrary content.
Here is a sample application demonstrating this, in the context of implementing openFile() on a ContentProvider.
is there any libraries to convert SVG to JPG ? else than BATIK ?
i used BATIK but i found some problems like this exception :
java.lang.NullPointerException
at org.apache.batik.css.engine.CSSEngine.getCascadedStyleMap(CSSEngine.java:684)
at org.apache.batik.css.engine.CSSEngine.getComputedStyle(CSSEngine.java:755)
at org.apache.batik.bridge.CSSUtilities.getComputedStyle(CSSUtilities.java:96)
at org.apache.batik.bridge.CSSUtilities.convertDisplay(CSSUtilities.java:509)
at org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(GVTBuilder.java:176)
at org.apache.batik.bridge.GVTBuilder.buildComposite(GVTBuilder.java:148)
at org.apache.batik.bridge.GVTBuilder.build(GVTBuilder.java:76)
at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(SVGAbstractTranscoder.java:165)
at org.apache.batik.transcoder.image.ImageTranscoder.transcode(ImageTranscoder.java:86)
at org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(XMLAbstractTranscoder.java:132)
this is my code :
JPEGTranscoder transcoder = new JPEGTranscoder();
transcoder.addTranscodingHint(JPEGTranscoder.KEY_XML_PARSER_CLASSNAME,
"org.apache.crimson.parser.XMLReaderImpl");
transcoder.addTranscodingHint(JPEGTranscoder.KEY_QUALITY,
new Float(1.0));
TranscoderInput input = new TranscoderInput(new FileInputStream("C:/Taha/SmartPlannerNew/rectangles.svg"));
OutputStream ostream = new FileOutputStream("C:/Taha/SmartPlannerNew/out.jpg");
TranscoderOutput output = new TranscoderOutput(ostream);
try {
transcoder.transcode(input, output);
} catch (TranscoderException e) {
System.out.println("error***************************************************************************************************************************");
e.printStackTrace();
}
System.out.println("done.");
ostream.close();
System.exit(0);
can any one help me please ?
Batik is exactly what you are looking for, is totally stable, and there really is not much else.
You can read the handy official tutorial on using the transcoder portion of batik:
http://xmlgraphics.apache.org/batik/using/transcoder.html
If you are still having trouble, try posting the code that you are using that causes the error, and a complete stack trace. Somebody here will be able to help you.
my mistake was that i was using different versions of jar files i deleted all my jars and downloaded a new set of jars from the same