I want to code an audio player in Java. java.JavaFX has a very nice support for mp3 playing but I want in my player also the possibility to listen to radio.
The problem is I have searched for some time and I didn't find something that works like I want:
MP3SPI - this is nice but just wont
play some streams
vlcj - I've tested the latest version
1.2.0 but was with a beta version of VLC so I had times when the stream
just stopped for no reason.
NativeSwing's windows media player
but that is a heavyweight component
and also I don't want to make it
dependable on WMP.
So I'm kind of out of luck. Well guys If you know more about this topic please share it!
Thank you!
MP3 playback in Java is a bitch. In nearly any case it's not worth the work you put in it.
However, this is something that worked for me. It can easily be recoded to play Shoutcast streams.
JavaLayer (library behind MP3SPI) is a mature project and should handle most streams, can you post some streams that it can not read? Check that other players using JavaLayer, like jlGUI, can play these streams. Maybe it's something with your code.
Related
Well, i want to call from my code and when the other persons answered my call send a audio clip in the audio streaming, i was ready is possible but also that isnt, help please.-
So, multiple questions in one. I'll answer all of them, mostly so you can get the keywords you can search for.
Setting up a call programatically, perfectly possible and quite easy
Playing an audio file into the call, not so trivial. Using the Java API for Android, you just can't do it. Anyhow, you can create a C application which can play an audio file, use it in your Android app (NKD and JNI required here), and give it control of the microphone.
If you are comfortable using C and think you can learn how to use NDK and JNI, you can do it. If you're gonna need it to be done using Java... right now you will just not be able to do it.
pd: if you are thinking about playing a file in the speaker and hope it to get into the microphone, it won't work on most of the devices out there. There are quite good echo cancellation chips out there.
I am an average java developer and i am trying to come up with a browser that is developed entirely in java. I want that my browser must be able to play youtube videos, and for that i was planning to use JMF.
Here are my questions:
1) can JMF be used to stream and play videos from links like youtube. If yes, can Some one please point to a demo link(a basic one will do, rest i will develop)
2) If that is possible, should we use JMF or VLCJ? If you recommend VLCJ, where can i find "libvlc"? I had a hard time looking for it.
Thanks to everyone for their help in advance
JMF seems to be abandoned, so VLCJ is a better choice
you can find libvlc.dll here . Pick the biggest. Or just install VLC player.
JMF is quite obsolete right now. It's so old that its player won't open any of the video files used nowadays and if you're trying to capture webcam video you won't be able to detect your camera if you're running on Windows 7.
I heard Xuggler is fine but I really couldn't get it to work after trying hard for a few days so I would recommend VLCJ, which works great and its really easy to set up.
The libraries used in VLCJ are included in VideoLAN's folders when installing VLC. Just install VLC's last version and go to C:/Program Files/VideoLAN/VLC/ and there you'll find both libvlc.dll and libvlccore.dll
VLCj will play Youtube videos easily, JMF won't and is long dead - I wouldn't touch it for any new projects personally. If you're going down the VLCj route though you'll want to look at out of process players, you can't reliably include multiple players in process.
You cant do youtube with JMF. Also check out Xuggler
What actually exist to solve Java Video ? It does not work in my linux box, JMF cant detect even my webcam. ex: http://i.stack.imgur.com/Vic0o.png
JMF - works in Mac, i guess no ? Cause in CentOS/Fedora it does not detects my Video camera.
FMJ - ? Does those requires native separate installation ?
LTI-civil ? Does those requires native separate installation ?
Xuggler ? Does those requires native separate installation ?
My most important feature is: Can i use other java video libraries to make eye contacts video frame, means 1 screen from (Sender, Receiver, Third party) 3 to 4 participant in 1 video screen.
Follow up:
Java video does not work: http://i.stack.imgur.com/d6f5V.png
I am now wondering so many years Java remains but Video they didnt completed yet.
Where Adobe Flex/Air is just a few lines of code and its done (still experts dont belive in Flex/Air, i must research why, maybe quality issue and restricted raw access).
Cant figure it out in my small brain about Java and its Video solution.
Many more reason ... researching...
Will, Appreciate more advise!
JMF is sadly neglected from Sun, and FMJ was started to rectify this. I would start with FMJ and see how it works for you.
dsj - DirectShow is also a good choice and dont need a separate installation.
http://www.humatic.de/htools/dsj.htm
How can I get video and audio streams from web cameras with Java (in a cross-platform way)?
For example, we have a computer with 3-4 USB web cameras; we want to get their streams and make them visible in the user interface. How can we perform such a thing? I need code for a simple app which would find ALL cameras on the computer and let us select camera to wach. Can any one, please share such one?
With java media framework JMF or FMJ
Here is an example with JVM
I see your comment about the solution needing to be "pure" java, but this is really "nearly" impossible. You will need to use some sort of native library for accessing the devices, with that being stated; I suggest that you look at Xuggler as your solution. Xuggler supports Windows, Mac, and Linux and they also offer example code for handling audio and video. Lastly the library is FREE.
Webcam capture example: http://xuggle.googlecode.com/svn/trunk/java/xuggle-xuggler/src/com/xuggle/xuggler/demos/DisplayWebcamVideo.java
While Xuggle does not have an example of microphone capture, you can find samples on the mailing list or you could use code written by the packet-mulitbroadcaster project found here: https://code.google.com/p/packet-multibroadcaster/
You can try my solution. It uses OpenCV to capture the image and jetty server to transmit it via WebSocket. The example has three classes and it will be easy to understand.
Now I can send only video, but I'm working on audio aswell.
I'd use flex. It can be relatively easily integrated with java backend.
UPD:
Pure Java needed
Then you should consider JavaFX solutions. I'm not a big expert in javafx, I've only written some basic test applications, but I'm sure it's a modern way of solving described problem with pure java.
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).