I've had a look at that code - I'm still fairly unsure of myself when it comes to native java code for android...let alone java code full stop but I've tried putting the following together and I get an error on compile about catching an exception not being done...not sure I understand...here is what I have in my code:
"android.java"
import android.media.MediaRecorder;
class SoundMeter {
static final private double EMA_FILTER = 0.6;
private static MediaRecorder mRecorder = null;
private static double mEMA = 0.0;
static void start() {
if (mRecorder == null)
{
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mRecorder.setOutputFile("/dev/null");
try
{
mRecorder.prepare();
}catch (java.lang.SecurityException e) {
android.util.Log.e("[Monkey]", "SecurityException: " + android.util.Log.getStackTraceString(e));
}
try
{
mRecorder.start();
}catch (java.lang.SecurityException e) {
android.util.Log.e("[Monkey]", "SecurityException: " + android.util.Log.getStackTraceString(e));
}
mEMA = 0.0;
}
}
static void stop() {
if (mRecorder != null) {
mRecorder.stop();
mRecorder.release();
mRecorder = null;
}
}
static float getAmplitude() {
if (mRecorder != null)
return (float)(mRecorder.getMaxAmplitude()/2700.0);
else
return 0;
}
static float getAmplitudeEMA() {
float amp = getAmplitude();
mEMA = EMA_FILTER * amp + (1.0 - EMA_FILTER) * mEMA;
return (float)mEMA;
}
}
and in monkey
Strict
Import mojo
Import "android.java"
Extern
Function StartRecord:Void()="SoundMeter.start"
Function StopRecord:Void()="SoundMeter.stop"
Function GetAmplitude:Float()="SoundMeter.getAmplitude"
Function GetAmplitudeEMA:Float()="SoundMeter.getAmplitudeEMA"
Public
Function Main:Int()
Local myapp:MyApp
myapp = New MyApp
Return 0
End Function
Class MyApp Extends App
Method OnCreate:Int()
StartRecord()
SetUpdateRate 30
Return 0
End Method
Method OnUpdate:Int()
Return 0
End Method
Method OnRender:Int()
Cls
DrawText String(GetAmplitude()),0,0
Return 0
End Method
End Class
and the error I'm getting on compile:
compile:
[javac] C:\Program Files\Android\android-sdk\tools\ant\main_rules.xml:384: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[javac] Compiling 2 source files to C:\MonkeyPro44\MonkeyPro44\androidgps\androidsoundmeter.build\android\bin\classes
[javac] C:\MonkeyPro44\MonkeyPro44\androidgps\androidsoundmeter.build\android\src\com\monkey\MonkeyGame.java:1663: unreported exception java.io.IOException; must be caught or declared to be thrown
[javac] mRecorder.prepare();
[javac] ^
[javac] Note: C:\MonkeyPro44\MonkeyPro44\androidgps\androidsoundmeter.build\android\src\com\monkey\MonkeyGame.java uses unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 1 error
BUILD FAILED
I feel as if each time I post one of these questions I end up basically just asking for the code...sorry about that. EDIT - I must admit I don't really know what I'm doing with the java code..
|