I have a few questions related to Sun, Audio-player and Sound Input/Output
Why is the sun.audio.AudioPlayer package not part of the Java API? Some info is here instead: http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6b14/sun/audio/AudioPlayer.java Yet it is still part of the default JDK build I am using.
I have tried using JMF and spent half the day screw balling around with it, to no real avail. I managed to import the jmf.jar into Eclipse I tried a demo script and it still spat out errors like nobody business. Considering its abandoned now?!? Java does however provide a link for a relatively new version: http://www.oracle.com/technetwork/java/javase/download-142937.html I am a little concerned however how at the bottom of the page the following is written "false,,,,,,,"?
Whats the best package to use for audio I/O and manipulation in your opinion?
I just want to work on a project and I though an MP3 player would be a nice place to start as I can do a little swing. However it seems to be rather difficult as from what I have read Java is not really very keen on making mp3 and audio manipulation packages.
sun.audio is undocumented
Like other sun.* packages, it is undocumented and it might disappear.
Java Media Framework is old
It's an optional package, not part of the SE and hasn't been updated in a long time. Oracle has a page on it and it's still available but, well, who knows what will happen to it.
javax.sound is part of the SE
This is the current Java sound implementation, it is part of the SE and the tutorial for it can be found here. If you want to use audio in Java this is what you should learn because it's official, it works, it gets updated sometimes and it is well-documented.
javax.sound does not play mp3
Why is that? Despite being ubiquitous in file systems, mp3 has a history of licensing and patent issues. Mp3 is a minefield and this may be why Sun/Oracle has not put effort in to supporting it. (If this is why, I don't blame them.)
If you really want to play mp3 there are some third-party decoders floating around on the web. There is no point in recommending one because all of them will read mp3.
JavaFX does play mp3
Use a javafx.scene.media.MediaPlayer. See javafx.scene.media/Supported Media Types. JavaFX is part of the JRE/JDK as of Java 8 (and new versions of Java 7) and will (probably) eventually supersede several SE APIs like javax.sound and javax.swing.
Related
I have a few questions related to Sun, Audio-player and Sound Input/Output
Why is the sun.audio.AudioPlayer package not part of the Java API? Some info is here instead: http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6b14/sun/audio/AudioPlayer.java Yet it is still part of the default JDK build I am using.
I have tried using JMF and spent half the day screw balling around with it, to no real avail. I managed to import the jmf.jar into Eclipse I tried a demo script and it still spat out errors like nobody business. Considering its abandoned now?!? Java does however provide a link for a relatively new version: http://www.oracle.com/technetwork/java/javase/download-142937.html I am a little concerned however how at the bottom of the page the following is written "false,,,,,,,"?
Whats the best package to use for audio I/O and manipulation in your opinion?
I just want to work on a project and I though an MP3 player would be a nice place to start as I can do a little swing. However it seems to be rather difficult as from what I have read Java is not really very keen on making mp3 and audio manipulation packages.
sun.audio is undocumented
Like other sun.* packages, it is undocumented and it might disappear.
Java Media Framework is old
It's an optional package, not part of the SE and hasn't been updated in a long time. Oracle has a page on it and it's still available but, well, who knows what will happen to it.
javax.sound is part of the SE
This is the current Java sound implementation, it is part of the SE and the tutorial for it can be found here. If you want to use audio in Java this is what you should learn because it's official, it works, it gets updated sometimes and it is well-documented.
javax.sound does not play mp3
Why is that? Despite being ubiquitous in file systems, mp3 has a history of licensing and patent issues. Mp3 is a minefield and this may be why Sun/Oracle has not put effort in to supporting it. (If this is why, I don't blame them.)
If you really want to play mp3 there are some third-party decoders floating around on the web. There is no point in recommending one because all of them will read mp3.
JavaFX does play mp3
Use a javafx.scene.media.MediaPlayer. See javafx.scene.media/Supported Media Types. JavaFX is part of the JRE/JDK as of Java 8 (and new versions of Java 7) and will (probably) eventually supersede several SE APIs like javax.sound and javax.swing.
This is actually a question about the Java FX feature request process, and how to understand the information on JIRA. I find the jungle of forums and roadmaps and discussions completely unnavigable.
Specifically, the feature I'm interested in is video (e.g., webcam) capture:
JavaFx has come a long way, and I've recently found its realtime video capabilities to be functioning well. However, without video capture it cannot be described as a real rich media development platform. The feature request at JIRA is 5 years old and there are many frustrated users commenting on this continued absence: https://bugs.openjdk.java.net/browse/JDK-8090438. If I understand this correctly, this page tells me that Java FX 9 is when this feature will be introduced.
My question is: how do I know for sure when to expect video capture implementation in Java FX (if at all)?
I'm afraid that 'for sure' nobody can tell us when video support is integrated - not even the guys from oracle.
If you need video support now i would recommend openimaj from http://www.openimaj.org. They support the software for win, linux and arm.
My question is: how do I know for sure when to expect video capture implementation in Java FX (if at all)?
Simple answer - you don't. I wouldn't even expect it in 9 (they generally use that as a placeholder to mean some future release, rather than guaranteeing it'll be in JFX9.)
The JavaFX media capabilities are much better than they once were, but still lacking; there certainly doesn't appear to be a dedicated media team working on JFX as there once was. If you really need something like this, I'd suggest using an external library (VLCJ works well for me, and has much better format support for playback than JFX too.)
So far I only found two ways:
throw exception
play nothing
ad.2. Pretty recent code (2010)
http://www.developerfusion.com/article/84314/wired-for-sound/
but does nothing, not sound at all.
ad.1. For example:
Trouble playing wav in Java
http://www.anyexample.com/programming/java/java_play_wav_sound_file.xml
https://stackoverflow.com/a/2433454/210342
All I get is exception "Audio Device Unavailable". As this article (2008) -- lsof |grep snd — how to free a linux sound device -- explains Java has to get exclusive access to audio device.
However I cannot afford such condition. I use sound to notify myself on long running process (several hours), I cannot get rid of all sounds (including those forced via Flash ads) just to make Java comfy.
So for now I use total extreme -- I simply launch external program: https://stackoverflow.com/a/8370223/210342 . This is ugly as hell because well new program is launched just to make notification.
Question
Is there currently a way to play a WAV file:
on Linux,
in cooperative way (during Java playback there may be other audio played as well),
which makes sound,
in Java (no launching external programs)?
Java 1.6, openSUSE 11.4
Have you tried the Java Media Framework (JMF)?
The Java Media Framework API (JMF) enables audio, video and other
time-based media to be added to applications and applets built on Java
technology. This optional package, which can capture, playback,
stream, and transcode multiple media formats, extends the Java 2
Platform, Standard Edition (J2SE) for multimedia developers by
providing a powerful toolkit to develop scalable, cross-platform
technology.
This site provides a simple swing application to capture and play wav files
http://www.java-tips.org/java-se-tips/javax.sound/capturing-audio-with-java-sound-api.html
You can modify and use the code from the below site
http://www.anyexample.com/programming/java/java_play_wav_sound_file.xml
Cant you simply create a new thread whenever the play action is needed. So that the playing continues irrespective of the background processes
So, thanks to AT answer I drifted from JMF to JMF problems, and that led me to VLC-J. And this is the answer -- in order to use multimedia in Java program simply don't use Java (pity, btw. that Java in year 2012 does not have reliable multimedia layer, gee.).
Marking as solved, because VLC-J allowed me to play audio without problem.
Main project site:
http://code.google.com/p/vlcj/
Minimal playback program:
http://code.google.com/p/vlcj/source/browse/trunk/vlcj/src/test/java/uk/co/caprica/vlcj/test/minimalmp3/Mp3Test.java
Java has this support built in (available in javax.sound, javax.sound.sampled packages) on 1.4+ version. It works colaboratively with other applications on the system as it uses platform mixer (ALSA or PULSE)
You would have thought that tere is a simple solution to this but there isn't :(
My application needs to capture a stream from a USB/firewire (or whatever is the connection) connected camera (result would be a file like output.flv). I would prefer that I can detect all connected cameras and choose which one to use (one or more at the same time --> one or more output files). Application has to be cross platform.
Found libraries:
Xuggle - not very good camera support. Good for manipulating over images and video.
JMF - an old API but if I can use it, I will. I don't see a MAC OS X link on downloads page.
FMJ - looks like a better version of JMF but a can't find a way of installing it.
LTI-CIVIL - FMJ uses it. It looks like it only captures images from camera (not video). I could use Xuggle to create a video from images taken from LTI-CIVIL. And like FMJ, it is difficult to install.
What are your suggestions on this one?
I'd recommend VLCj for this - it should be able to stream from webcams onto a Java canvas without any difficulties. It uses native code so you need to provide libvlc.so / dll but from there on it should work on all the major platforms (Windows, Mac, Linux).
You may need to look at out of process players for complete reliability which is a bit more complex (see here for my efforts so far) but once you've got that in place it should work fine.
There really is no good camera support for Java. You will have to use native code, tailored for each platform, through JNI to get video capture for your project.
There's a related question here. Basically they're suggesting OpenCV wrapped with JNI.
I need simple video playback in Java.
Here are my requirements:
PRODUCTION QUALITY
Open and decode video files whose video and audio codecs can be chosen by me. I.E I can pick well behaving codecs.
Be able to play, pause, seekToFrame OR seekToTime and stop playback. Essentially I wish to be able to play segments of a single video file in a non linear fashion. For example I may want to play the segment 20.3sec to 25.6sec, pause for 10 seconds and then play the segment 340.3sec to 350.5sec, etc.
During playback, video and audio must be in sync.
The video must be displayed in a Swing JComponent.
Must be able to use in a commercial product without having to be open source (I.E. LGPL or Comercial is good)
My research has led me to the following solutions:
Use Java Media Framework + Fobs4JMF
http://fobs.sourceforge.net/f4jmf_first.html
I have implemented a quick prototype and this seems to do what I need. I can play a segment of video using:
player.setStopTime(new Time(end));
player.setMediaTime(new Time(start));
player.start();
While Fobs4JMF seems to work, I feel the quality of the code is poor and the project is no longer active. Does anyone know of any products which use Fobs4JMF?
Write a Flash application which plays a video and use JFlashPlayer to bring it into my Java Swing application
Unlike Java, Flash is brilliant at playing video. I could write a small Flash application with the methods:
open(String videoFile),
play(),
pause(),
seek(int duration),
stop()
Then bring it into Java using JFlashPlayer which can call Flash functions from Java.
What I like about this solution is that video playback in Flash should be rock solid. Has anyone used JFlashPlayer to play video in Java?
Write a simple media player on top of Xuggler
Xuggler is an FFMpeg wrapper for Java which seems to be a quite active and high quality project. However, implementing the simple video playback described in the requirements is not trivial (Seeking in particular) but some of the work has been done in the MediaTools MediaViewer which would be the base upon which to build from.
Use FMJ
I have tried to get FMJ to work but have had no sucess so far.
I would appreciate your opinions on my problem.
Can a brother get a shout out for Xuggler?
In my mind, VLCJ is the way forward for this type of thing. I love Xuggler for encoding / transcoding work, but unfortunately it's just so complicated to do simple playback and solve all the sync issues and suchlike - and it does very much feel like reinventing the wheel doing so.
The only thing with VLCJ is that to get it to work reliably with multiple players I've had to resort to out of process players. The framework wasn't the simplest thing in the world to get in place, but when it's there it works beautifully. I'm currently running 3 out of process players in my app side by side with no problems whatsoever.
The other caveat is that the embedded media player won't work with a swing component, just a heavyweight canvas - but that hasn't proven a problem for me at all. If it does, then you can use the direct media player to get a bufferedimage and display that on whatever you choose, but it will eat into your CPU a bit more (though no more than other players that take this approach.)
JavaFX has a number of working video and audio codecs builtin. It's likely to be the solution with the broadest support at the moment.
I've been using jffmpeg in the same way you use FOBS, it works pretty well, although I haven't compared them.
I would also love to see an easy way to interface with native codecs the way that JavaFX does, but there doesn't seem to be real integration between JavaFX and Java.
There has also been some work trying to get the VLC library libvlc into java. I haven't tried it yet and would be interested to hear back from anyone who has.
haven't tried Xuggler (which i'm interested in) but I'm having a good time with VLCJ. The drawback I find in it is only that you have to have VLC installed prior to your application.
I'd recommend using MPV. You can use it in combination with JavaFX quite easily, see this example.
In short, you use a little JNA magic to use the MPV native libaries directly, and then let the video display on a JavaFX stage. If you use a child stage, you can even overlay JavaFX controls on top of the video (with full transparancy support).
VLC (with VLCJ) can be used in a similar fashion, but I find that the MPV solution performs better (faster seek and start times).