Error while playing some MP3s using JavaZOOM BasicPlayer classes - java

Here is the stack trace:
java.io.IOException: Resetting to invalid mark
at java.io.BufferedInputStream.reset(BufferedInputStream.java:433)
at org.tritonus.share.sampled.file.TAudioFileReader.getAudioInputStream(TAudioFileReader.java:324)
at javazoom.spi.mpeg.sampled.file.MpegAudioFileReader.getAudioInputStream(Unknown Source)
at javazoom.spi.mpeg.sampled.file.MpegAudioFileReader.getAudioInputStream(Unknown Source)
at javax.sound.sampled.AudioSystem.getAudioInputStream(AudioSystem.java:1179)
at javazoom.jlgui.basicplayer.BasicPlayer.initAudioInputStream(Unknown Source)
at javazoom.jlgui.basicplayer.BasicPlayer.initAudioInputStream(Unknown Source)
at javazoom.jlgui.basicplayer.BasicPlayer.open(Unknown Source)
at BasicPlayerDemo.play(BasicPlayerDemo.java:49)
at BasicPlayerDemo.main(BasicPlayerDemo.java:24)
Seems that other people are also having this problem:
Jukebox: no sound?
Stack trace on player state update
Any reason for this? I am trying to make a simple Java Swing music player using JavaZoom classes.

There is a solution for this problem at (pelzkuh.de blog) It is in German but mainly says that the cause is an outdated library mp3spi1.9.4.jar. You have to replace it with the new one mp3spi1.9.5.jar. Links are provided in the pelzkuh blog entry.

The thread with answers alludes to something I have struck before.
MP3 is hardly any sort of 'standard' - with many extensions to the basic format. Java Sound based apps. will generally only deal with some of those types, and even if that were not the case
Media players generally go to considerable effort to play 'any rubbish file' (including invalid ones) thrown at them. It would be a major effort to replicate that ability.
So is there no simple solution to this? Should I just ignore such MP3s?
No
That sounds pretty easy (simple). Skip them & go to the next track. Pop a dialog or add it to a log if the user chooses 'high feedback' in the player options.
Actually I'm making a mini-project for my college, so it doesn't look good if this player doesn't play certain files.
I'd check that with the people marking it. If they are expecting you to provide support for 'any file thrown at it' in a college project, they need to pull their head out of the clouds. I'll bet I could make files that play on one 'major player' but cause the next to lock up & die (OK.. thinking more of some recent video attempts, but the same basic principle applies). 'Handling media' is tricky.
..the college isn't expecting anything, since I chose to create this myself. I didn't know that handling media is tricky. Now if they ask, I can tell them that!
I suggest supplying the player complete with a play list and media controlled by you (and sure to be compatible with your player). You can find 3 basic, distributable MP3 tracks at my media page. Those are:
(parsable by) the JMF MP3 codec
..so JavaZoom should be able to load them as well.

Related

Java record audio only when someone is speaking

I'm building a voice assistant. I have a working audio recorder that I can stop and start easily.
I just want to be able to detect when the user is actually speaking (it isn't silent) so that I only record what they say, stopping the recording when they stop speaking.
I've been struggling to find a way of doing this. Does anyone have any ideas?
Edit:
So far I've only found Sphinx4 to be able to detect a voice input but it's been flaky at best and I haven't been able to use it to trigger my sound recorder.
I also had a similar project and am using Sphinx4. As the OP said, using Sphinx4 to detect when a user is speaking (and just as importantly when they stop speaking) was an issue. As they said, it was "flaky" at best. Fortunately, I came up with a solution that hopefully helps others that stumble along here.
There are two solid ways I found that worked with Sphinx:
1st Solution: Get the Sphinx4 source and copy the classes from package edu.cmu.sphinx.api into your project. There were about 9 files in there, starting with AbstractSpeechRecognizer and ending in StreamSpeakRecognizer. Since the OP is talking about voice recognition, it is assumed that their inputstream is from a microphone, which makes the LiveSpeechRecognizer and Microphone classes important. Change the imports in your main java activity and import that package (or individual classes as necessary).
From there, there are multiple options. I ended up writing a method in LiveSpeechRecognizer and Microphone that used the results from [LiveSpeechRecognizer].getResult() and putting a shared boolean in there to recognize when a voice is detected. LiveSpeechRecognizer returns results whenever someone finishes speaking, so basically you just set the boolean when the first audio is detected, and detect the voice after the next results come in. Add a timer (I used java's Executor) in a separate thread to detect how long since the last words were detected (i.e. 2 seconds). This way if something goes wrong with the mic or they say a really short sentence, it'll still detect the "end".
In this solution, extending sphinx.api isn't strictly necessary, however I found the results a lot faster when modifying Microphone directly instead of waiting for the results from the main activity.
2nd Solution: You could also modify the source for Sphinx4 so that when "noise" is detected below a certain level it means the user has stopped talking. Sphinx is continuously monitoring the microphone using Java's TargetDataLine. Mess around with the threshold in which it filter's out noise and implement a listener when it changes too much. This approach is absolutely awful for voice recognition, but the OP wanted to detect when a person starts and stops talking, which this will do.

Matching Dots in Java

I`m developing a new robot for a Rescue Competition, and we want to use SLAM to do the mapping and Localization.
One of the main problems is to match a list of dots with another list of dots.
We are running the robot on an Android 2.4Ghz, with a self made app.
Does anyone know about any Java Library for ICP (Iterative Closest Point) or PSM (Polar Scan Matching) algorithm?
If not, do you know how to implement it in Java?
Thanks
This is a pretty vague answer, but you could try your luck with the MITK (Medical Imaging Toolkit) Framework. Some filters there employ the ICP Algorithm. Since the whole thing is open source you should be able to find what you need there. It's all written in C++ though. Plus Side: They are working on an improved version, the Anisotropic ICP. Also check the point based registration module from the 3m3 branch of MITK: The Point Based Registration Module

Screensharing via Java Applet

I am looking for an addition for our "livestream and podcast" solution, which uses a camera to film speeches in our house.
It has been requested to view the slides of our speakers directly as a image in the webbrowser instead of the video stream. We don't want/can not install software on the speakers laptop, so I thought about a Java applet, which the speaker can just run via a webbrowser.
So what I need is technically this:
[speakers laptop] -> [Screencapture every N seconds via applet on a webpage] -> [Displaying the screen of the speaker on a different webpage for the external viewers]
I know there are Java applications which do record the screen, but save the file output locally. I need something that does the same, but sends the image to the server. On the server side I thought about a websocket.js accepting and displaying the image (other suggestions are welcome).
It would be great if somebody could help me out here. Btw, I never programmed in Java, so telling me which frameworks I need won't really help me.
Thanks!!
I was recently asked to evaluate possibilities for live screen-cast via applet. Most video APIs do not support codecs that have high enough compression (e.g. JMF). Some APIs can do advanced formats (JFFMPEG, Xuggle) but also use natives. While natives are normally no problem for an app. launched (free floating) using Java Web Start or a Plug-In 2 applet, the makers of Xuggle identify 'the order of loading natives' as a problem (e.g. won't work) for both JWS and applets.
It is a pity that more than a decade into its development, Java has no reasonable API for video capture/processing that can be deployed for a wide use (applet/JWS based - for the 'general public') GUI.
Perhaps you can find a solution using Flash.
Update 1
In fact, I do not need the screen to be recorded as a video.
In fact, you mentioned much of that in your initial question, but I focused on just a few keywords before drafting a reply. My bad. :P
OK.
Getting an image is relatively easy. An applet would need to be trusted in order to get a screenshot, but once trusted, it is just a few lines of code to get the image.
Encoding the image to JPEG of particular quality/compression setting (in memory) is also doable.
Sending the image to the server would depend on the size in bytes and connection speed, but one image with a high compression, every 10 seconds, should be doable. The server would need to implement functionality to accept the image.
As far as displaying the image on the client, it seems you already have some ideas based around JS. If you can make that work that would be optimal, since it can then be viewed in browsers with no Java.
I would still recommend you deploy the app. to the 'speaker' using Java Web Start, rather than embed an applet. A JWS app. will give you less deployment & maintenance troubles, and the JWS launch is ..nicer. Further, a free floating frame launched using JWS can minimize itself (or in later JREs, become transparent), during the action of taking a screen image - thereby capturing everything on the screen except itself.
Update 2
I actually found this code here.
That is ..horrible. Not the code, the site. When I visited it I got a message saying a pop-up had been suppressed (fair enough). Then there was the irritating 'vibrating dialog' hovering in the middle of the page (and following the scroll). You click the little x to see - another tab opened with yet another floating dialog, saying some other rubbish about how "You've won.." - with sound loud enough to drown out my high volume trance/dance playlist.
Then after closing that the hell out of my FF, I go back to the original page, close the damn 'dialog', scroll down & see.. a red background to the code (shudder). That is as far as I could manage. I closed the page with the code.
Try this code instead, for a single screen-shot.
Would it be possible to use this on the client side..
Yes.
.. and receive it with javascript on the server side?
Not really. Unless you mean an IIS based server running Microsoft's JScript. JavaScript is a client side technology.
For security reasons, servers need to protect themselves. E.G. From:
Someone creating a slavebot that uploads all the 1000s of docs on the slave machine's to the site - to make it crash.
People high-jacking your server for storing and serving bestiality porn (or worse).
Because of things like that (bad people have lots of imagination), while servers can easily accept uploads, they are generally not configured by default to allow them.
.. (I don't want Java on my server ;-)
It can be done using PHP, ASP, CGI etc. It does not need Java specifically, but it does need some active involvement from the server, if only to check the size of what is being uploaded and abort if it gets too large!
..Will take a look at the link you posted, but as I said, I can't program in Java, though I can understand some of it. Thanks!
It sounds like you'll need some help getting the server-side of it ready, as well. It is trivial for someone that knows how (not me), but a potential security nightmare for the inexperienced.
Update 3
where do I add the function to send the picture?
Sorry. I've not tried to implement that - you'd want to want to encode it to JPEG before sending, to reduce the size. See this code for how to provide an adjustable compression/quality where the user can see the effect.
There are various ways to get an image to a server. E.G. sockets, HTTP, FTP.. AFAIU it would depend on how the server is accepting it. I am unfamiliar with the specific term 'websocket' or the node.js script. Can you link to what you mean?
..the old code added to pastebin, so it's readable
Smart thinking. I notice it uses sockets, it was in the back of my mind that sockets would be best for this, since they have low overhead and short wait times.

Android Pros: How to wrap PayPal's MPL?

I have no Java experience and prefer Visual Basic; I've found a very nice translation IDE called Basic4android (www.basic4android.com). It works by interpreting a scripting language that's similar to Visual Basic and then using it to generate and compile native Java code. Rather ingenious, if you ask me. In fact I believe I found it from a reference here on StackOverflow.
I'm having some trouble wrapping PayPal's Mobile Payments Library:
www.x.com/community/ppx/xspaces/mobile/mep (scroll down for the HTML Tutorial)
I need to do it in a way that promotes the library's functionality so that B4A can in turn expose it to the Android device (emulator in this case). I've made some halting progress so far, but now I'm stuck on NullPointerExceptions occurring deep within the MPL.
The saga is pretty well described in a thread at their forum:
http://www.basic4ppc.com/forum/additional-libraries-official-updates/8819-looking-download-link.html
Here's my wrapper and the generated code—download here—as only licensed users may access downloads in that particular forum section.
The latest NullPointerException occurs a few calls down from the initWithAppID function. The JD-GUI decompiler reports an internal error when it gets to the com.paypal.android.b.b class, so it doesn't appear to be possible to know exactly what's going on down there.
I'm certain this can be done; I just need to know how to open the proper communication channel between the device and the MPL.
I'm new at Java and I'm new at Android. Quite a combination, wouldn't you say?
It turns out the problem is in the way PayPal bundles their resource files; non-Eclipse projects can't get at them.
More info on the original B4A thread.
Thanks,
Jeff
I think if you ask here about something that generates code for you, you won't be provided with any answers because you can't give any useful source code or something. Also, if you use something like this tool, you never know what it's generating. Also, you can't fix any occurring errors with the generated code... I could go on and on and on...
If you want to use Android the way it's supposed to be used, you'll need to learn Java and Android. If you are good with VB, this shouldn't be that hard. And this is what anyone is going to tell you.

Converting equations to java for android?

I am a cameraman and I want to make an app for my Moto Droid that will
calculate my depth of field given four inputs.
I am literally brand
new to javascript and this programming stuff, so I was wondering if
anyone could help me out.
I have a very basic GUI set up using Droiddraw which allows me to
input my 4 variables, which are:
Focus (#+id/focust)
Focal Length (#+id/flt)
Aperture (#+id/apt)
Circle of Confusion (#+id/coct)
Equations for this calculation are located here
for example...
to get hyperfocal distance I need to get: ((f^2)/(N*c))+f
all of these variables will be drawn from inputs in the GUI, but I don't know how to call them, how to write the actual math, and how to address the results so I can make them appear in the "results area" on the bottom of the screen.
I've never done java before and I only want to make this app because the existing ones don't fit my needs.
Can someone help?
Thanks!
If I'm not mistaken, DroidDraw is a tool for building the XML user interface description used by the Java API. If you want to program for Android in JavaScript, something like PhoneGap might be a better choice. It lets you build real Android application using HTML and JavaScript.
On the other hand, if you want to use the XML and Java APIs, then you should probably run through the Android tutorials. The first one is Hello, World.
Since you're just getting started with programming, I can't stress tutorials enough. It's true that your idea shouldn't be too hard to implement, but you need to understand the basics first.
I don't mean to give the impression that one style (PhoneGap vs. Java and XML) is better. For your purposes, either should be fine. It's more a question of what you prefer. Java/XML is the paradigm supported by Google, and provides access to more functionality. On the other hand, if you already know HTML or JavaScript (or are interested in learning them), PhoneGap will certainly provide everything you need. I think PhoneGap is also intended to make it easier for beginners, though I haven't used it, so I don't know how successful they have been.
The XML file that is generated by DroidDraw can't be used within PhoneGap. If you do choose to use PhoneGap, then you will need to build the interface in HTML. You might be able to use something like DreamWeaver or FrontPage or one of any number of HTML editors to help you with this step.
The XML file is just a description of an interface. When you start your application, the Android platform uses this description to build the user interface that you see. Once that has happened, you can move data from the interface to Java, or from Java to the interface, without any hassle. You certainly won't be limited by the XML interface description - it's pretty flexible.
If you've been going through the Android tutorials, then it might be best to forget that I even mentioned PhoneGap. It's a wildly different alternative that is the right choice for some people and some applications. But the Android tutorials won't help you to understand it. I only brought it up because you mentioned JavaScript in your original post.

Categories

Resources