I cannot import sun.audio [duplicate] - java

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

Video capture in JavaFX

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.)

Sun, Audio-player and Sound I/O

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.

Build Android native library with Adobe Air

I'm currently working on an Android application built with Adobe Air sdk, in AS3. I was wondering if it's possible to compile a kind of UI library that I can import in a Android native application (Java). Basically, I would like to build my UI with Adobe Air, but the main part of my application with Java, the native way.
What I have in mind is to convert the adobe air-generated APK into a Jar file I would import in the native application project, and call some functions that display something on the Screen.
Is it possible? I think it may be possible, because when I don't import Adobe Air SDK in the application, I must install Adobe Air application with the Play Store to make my application working. I don't find lot of things on Google about that :s.
Thank you for your help.
Yes it can be done (in theory), but hold on to your hat, it's a bumpy ride!
I see it is a very old question, with a new bounty (the questioner has not logged on for 3 years!), but here we go...
This method goes to the heart of how android java apps are constructed and run (i.e. DEX, so it will work with adobe-air or ANYTHING, it is fundamental [general method]). (by the way you use the word native in a confusing way, native is commonly understood to mean the JNI (c++) library element of an app).
You say:
"What I have in mind is to convert the adobe air-generated APK into a
Jar file I would import in the native application project, and call
some functions that display something on the Screen."
Android programs are compiled into .dex (Dalvik Executable)[now called ART but binary compatible] files,
which are in turn zipped into a single .apk file on the device (with other things like the manifest and resources). (unzip a .apk and look inside).
A .jar file contains DEX files (zipped). (unzip a compiled .jar and look inside).
I have done some work like this before, here's a link to a tutorial and coding examples [tested by me] (in android studio + gradle) [custom build elements are usually needed (I also give an ant example)].
See my stack-overflow answer Dynamic loading of DEX files
This in theory answers your question, but it's fundamental stuff, complex and has limitations that make it hard to code and maintain (resources are a real pain in the a**e).
Question: This all seems very complicated and hard !
Yes it is ! It is an increadably silly an difficult thing to do! That is why we invented cross platform frameworks, (and for web based code javascript/css/html5...). Failing that PORT the code.
I'm more of a Flash/AS3 coder than Java so can't give you a full answer but...
A better approach might be to just render your SWF-based User Interface itself via Java code (as opposed to compiling SWF into APK format then trying to embed Flash APK inside Android APK).
This way your SWF can also communicate with Java functions (via AS3's external Interface class). Making it easier to trigger Java functions when a button on the SWF U.I is pressed etc..
You just have to find an SWF render library for Java.
Maybe check out SWFTools. Particularly the SWF Class looks promising. I have not tested this library but it might help you.
I am not a Adobe AIR developer at all, however, I have developed a few Android App with both native environment and with some kind of framework (specifically PhoneGap). So, may this can help you.
I don't think that there would be any tool which could directly convert mobile apps build using frameworks like Adobe AIR, PhoneGap or any other HTML5 based framework to a native Android app because technically it is very difficult and unfeasible to do a proper mapping between each and every element of HTML5 (or Flex element in your case) to a corresponding native control or logic. The best you can do is use plugin mechanism provided by your framework to interact with Java and vice-versa and basically that is why the framework is there. For most of HTML5 based frameworks there is a plugin mechanism which allows developer to interact with native functionality (like Background Services, Activity or any other native resource). Even these frameworks are build using the same modular or plugin based approach and there major functionality (accessing Camera, Audio, SD Card etc native resources) works like this. We have to enable that feature before using that in our app.
So, look for plugin type of mechanism in Adobe AIR.
Hope this helps.
Maybe this is a dirty way to help you, but you can :
Install the adobe air program in one computer
Copy the files of the install folder of the adobe air program
Embed all this files in the java application
Install the java application
Save the adobe air files in one folder
Start the adobe air with java (like you will do it with the console, a simple call to YourAirApp.exe)

Is there a way to play WAV files in a cooperative way on Linux in Java?

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)

Which Java library to use for record a video from a connected camera?

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.

Categories

Resources