How to set sample rate as 100KHz using AudioTrack in Android? - android

I'm developing an Android app that will play a specific audio. This audio is generated by code. My problem is that I need the sample rate up to 100KHz, but I got the error message as below. Could anyone know how to set sample rate as 100KHz with AudioTrack. Thanks.
PS: As I know, only AudioTrack could modify audio data, that's why I use AudioTrack
---------------code start-------------------
audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
100000,
AudioFormat.ENCODING_PCM_16BIT,
(int)minSize,
AudioTrack.MODE_STREAM);
---------------log start--------------------
> D/AndroidRuntime( 7952): Shutting down VM E/AndroidRuntime( 7952):
> FATAL EXCEPTION: main E/AndroidRuntime( 7952):
> java.lang.RuntimeException: Unable to start activity
> ComponentInfo{com.examples.audiotracktest/com.examples.audiotracktest.AudioTrackTest}:
> java.lang.IllegalArgumentException: 100000Hz is not a supported sample
> rate. E/AndroidRuntime( 7952): at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1830)
> E/AndroidRuntime( 7952): at
> android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1851)
> E/AndroidRuntime( 7952): at
> android.app.ActivityThread.access$1500(ActivityThread.java:132)
> E/AndroidRuntime( 7952): at
> android.app.ActivityThread$H.handleMessage(ActivityThread.java:1038)
> E/AndroidRuntime( 7952): at
> android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime(
> 7952): at android.os.Looper.loop(Looper.java:150) E/AndroidRuntime(
> 7952): at android.app.ActivityThread.main(ActivityThread.java:4293)
> E/AndroidRuntime( 7952): at
> java.lang.reflect.Method.invokeNative(Native Method) E/AndroidRuntime(
> 7952): at java.lang.reflect.Method.invoke(Method.java:507)
> E/AndroidRuntime( 7952): at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
> E/AndroidRuntime( 7952): at
> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
> E/AndroidRuntime( 7952): at dalvik.system.NativeStart.main(Native
> Method) E/AndroidRuntime( 7952): Caused by:
> java.lang.IllegalArgumentException: 100000Hz is not a supported sample
> rate. E/AndroidRuntime( 7952): at
> android.media.AudioTrack.audioParamCheck(AudioTrack.java:369)
> E/AndroidRuntime( 7952): at
> android.media.AudioTrack.<init>(AudioTrack.java:312) E/AndroidRuntime(
> 7952): at android.media.AudioTrack.<init>(AudioTrack.java:265)
> E/AndroidRuntime( 7952): at
> com.examples.audiotracktest.AndroidAudioDevice.<init>(AndroidAudioDevice.java:21)
> E/AndroidRuntime( 7952): at
> com.examples.audiotracktest.AudioThread.<init>(AudioThread.java:11)
> E/AndroidRuntime( 7952): at
> com.examples.audiotracktest.AudioTrackTest.onCreate(AudioTrackTest.java:29)
> E/AndroidRuntime( 7952): at
> android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
> E/AndroidRuntime( 7952): at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1794)
> E/AndroidRuntime( 7952): ... 11 more

100kHz is a non-standard sampling rate and most Android platforms only support the standard rates (ref. Wikipedia: Sampling Rate).
The closest standard rate is 96kHz (professional audio) but most phones don't support this high a rate. CD quality (44.1kHz) is widely supported and you might be lucky and get 48kHz (e.g. Nexus S).

Do check out this method in Audiotrack, audiotrack.setPlaybackRate(int sampleRateInHertz)

Related

Android javafxports NullPointerException

I'm getting a force close crash on a small Android app I made for school using Javafxports.
Here is the code and APKs
And the logcat returns this exception:
E/AndroidRuntime( 4474): FATAL EXCEPTION: JavaFX Application Thread
E/AndroidRuntime( 4474): Process: com.julioqc.superflush, PID: 4474
E/AndroidRuntime( 4474): java.lang.NullPointerException
E/AndroidRuntime( 4474): at com.sun.glass.ui.monocle.MonocleWindowManager$1.run(MonocleWindowManager.java:179)
E/AndroidRuntime( 4474): at com.sun.javafx.application.PlatformImpl.lambda$null$155(PlatformImpl.java:295)
E/AndroidRuntime( 4474): at com.sun.javafx.application.PlatformImpl$$Lambda$19.run(Unknown Source)
E/AndroidRuntime( 4474): at java.security.AccessController.doPrivileged(AccessController.java:52)
E/AndroidRuntime( 4474): at com.sun.javafx.application.PlatformImpl.lambda$runLater$156(PlatformImpl.java:294)
E/AndroidRuntime( 4474): at com.sun.javafx.application.PlatformImpl$$Lambda$6.run(Unknown Source)
E/AndroidRuntime( 4474): at com.sun.glass.ui.monocle.RunnableProcessor.runLoop(RunnableProcessor.java:92)
E/AndroidRuntime( 4474): at com.sun.glass.ui.monocle.RunnableProcessor.run(RunnableProcessor.java:51)
E/AndroidRuntime( 4474): at java.lang.Thread.run(Thread.java:841)
I/cm.log.servpro( 1334): [Privacy]/ com.google.android.googlequicksearchbox is not in contact list
W/ActivityManager( 726): Force finishing activity com.julioqc.superflush/javafxports.android.FXActivity
What is causing this error in my code??
EDIT: found out the issue is caused by some unsupported JavaFX 8 dialogs. Trying alternative.

Crash at startup on port to Cordova Crosswalk (Android)

I'm porting an existing android cordova app to cordova crosswalk.
Using cordova 4, crosswalk-cordova-10.39.235.9-x86 and Android SDK 19
The app crashes at startup with the following logs in logcat:
D/AndroidRuntime( 7208): Shutting down VM
W/dalvikvm( 7208): threadid=1: thread exiting with uncaught exception (group=0x41caeda0)
E/AndroidRuntime( 7208): FATAL EXCEPTION: main
E/AndroidRuntime( 7208): Process: myapp.cqa, PID: 7208
E/AndroidRuntime( 7208): java.lang.ExceptionInInitializerError
E/AndroidRuntime( 7208): at org.apache.cordova.CordovaActivity.makeWebView(CordovaActivity.java:295)
E/AndroidRuntime( 7208): at org.apache.cordova.CordovaActivity.init(CordovaActivity.java:348)
E/AndroidRuntime( 7208): at org.apache.cordova.CordovaActivity.init(CordovaActivity.java:323)
E/AndroidRuntime( 7208): at myapp.cqa.CordovaApp.onCreate(CordovaApp.java:31)
E/AndroidRuntime( 7208): at android.app.Activity.performCreate(Activity.java:5451)
E/AndroidRuntime( 7208): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
E/AndroidRuntime( 7208): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2358)
E/AndroidRuntime( 7208): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2452)
E/AndroidRuntime( 7208): at android.app.ActivityThread.access$900(ActivityThread.java:172)
E/AndroidRuntime( 7208): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1302)
E/AndroidRuntime( 7208): at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime( 7208): at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime( 7208): at android.app.ActivityThread.main(ActivityThread.java:5586)
E/AndroidRuntime( 7208): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 7208): at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime( 7208): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
E/AndroidRuntime( 7208): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
E/AndroidRuntime( 7208): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 7208): Caused by: java.lang.RuntimeException: java.lang.RuntimeException: Use SharedXWalkView if you want to support shared mode
E/AndroidRuntime( 7208): at org.xwalk.core.ReflectionHelper.handleException(ReflectionHelper.java:233)
E/AndroidRuntime( 7208): at org.xwalk.core.ReflectionHelper.handleException(ReflectionHelper.java:237)
E/AndroidRuntime( 7208): at org.xwalk.core.ReflectionHelper.init(ReflectionHelper.java:132)
E/AndroidRuntime( 7208): at org.xwalk.core.ReflectionHelper.loadClass(ReflectionHelper.java:199)
E/AndroidRuntime( 7208): at org.xwalk.core.XWalkPreferences.setValue(XWalkPreferences.java:112)
E/AndroidRuntime( 7208): at org.apache.cordova.CordovaWebView.<clinit>(CordovaWebView.java:890)
E/AndroidRuntime( 7208): ... 18 more
E/AndroidRuntime( 7208): Caused by: java.lang.RuntimeException: Use SharedXWalkView if you want to support shared mode
E/AndroidRuntime( 7208): ... 23 more
Any idea why it crashes ?
OK, after a night of sleeping, I realized I was using x86 crosswalk instead of the ARM one. Sorry for the dumb issue post...

Cannot load lib from /vendor/lib in android 4.0.3

I preinstalled app into /vendor/app, and lib into /vendor/lib. when I start app, exception caught:
> E/AndroidRuntime( 2446): at
> android.app.Activity.performCreate(Activity.java:4465)
> E/AndroidRuntime( 2446): at
> android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
> E/AndroidRuntime( 2446): at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
> E/AndroidRuntime( 2446): at
> android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
> E/AndroidRuntime( 2446): at
> android.app.ActivityThread.access$600(ActivityThread.java:123)
> E/AndroidRuntime( 2446): at
> android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
> E/AndroidRuntime( 2446): at
> android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime(
> 2446): at android.os.Looper.loop(Looper.java:137)
> E/AndroidRuntime( 2446): at
> android.app.ActivityThread.main(ActivityThread.java:4424)
> E/AndroidRuntime( 2446): at
> java.lang.reflect.Method.invokeNative(Native Method) E/AndroidRuntime(
> 2446): at java.lang.reflect.Method.invoke(Method.java:511)
> E/AndroidRuntime( 2446): at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
> E/AndroidRuntime( 2446): at
> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
> E/AndroidRuntime( 2446): at
> dalvik.system.NativeStart.main(Native Method) E/AndroidRuntime( 2446):
> Caused by: java.lang.UnsatisfiedLinkError: Couldn't load
> jni_factory_test: findLibrary returned null E/AndroidRuntime( 2446):
> at java.lang.Runtime.loadLibrary(Runtime.java:365) E/AndroidRuntime(
> 2446): at java.lang.System.loadLibrary(System.java:535)
My env is:
export LD_LIBRARY_PATH /vendor/lib:/system/lib
What should I do?
Try with system.load call with path to vendor lib

ActivityNotFoundException when include Android library

I have a test project which uses OI FileManager. I added that project to my test project as an Android library, then I call an Activitity in the library. It shows error:
E/AndroidRuntime( 1359): FATAL EXCEPTION: main
E/AndroidRuntime( 1359): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.androidcoretest/org.openintents.filemanager.FileManagerActivity}; have you declared this activity in your AndroidManifest.xml?
E/AndroidRuntime( 1359): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
E/AndroidRuntime( 1359): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
E/AndroidRuntime( 1359): at android.app.Activity.startActivityForResult(Activity.java:2817)
E/AndroidRuntime( 1359): at android.app.Activity.startActivity(Activity.java:2923)
E/AndroidRuntime( 1359): at com.androidcoretest.FileExplorerTest$1.onClick(FileExplorerTest.java:24)
E/AndroidRuntime( 1359): at android.view.View.performClick(View.java:2408)
E/AndroidRuntime( 1359): at android.view.View$PerformClick.run(View.java:8816)
E/AndroidRuntime( 1359): at android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime( 1359): at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 1359): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 1359): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime( 1359): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 1359): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 1359): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime( 1359): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime( 1359): at dalvik.system.NativeStart.main(Native Method)
When I add full path of that Activity in the Manifest, it generates another error.
<activity
android:label="#string/app_name"
android:name="org.openintents.filemanager.FileManagerActivity" >
</activity>
It shows:
E/AndroidRuntime( 1393): FATAL EXCEPTION: main
E/AndroidRuntime( 1393): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androidcoretest/org.openintents.filemanager.FileManagerActivity}: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.androidcoretest/org.openintents.distribution.EulaActivity}; have you declared this activity in your AndroidManifest.xml?
E/AndroidRuntime( 1393): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
E/AndroidRuntime( 1393): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
E/AndroidRuntime( 1393): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
E/AndroidRuntime( 1393): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
E/AndroidRuntime( 1393): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 1393): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 1393): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime( 1393): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 1393): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 1393): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime( 1393): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime( 1393): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 1393): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.androidcoretest/org.openintents.distribution.EulaActivity}; have you declared this activity in your AndroidManifest.xml?
E/AndroidRuntime( 1393): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
E/AndroidRuntime( 1393): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
E/AndroidRuntime( 1393): at android.app.Activity.startActivityForResult(Activity.java:2817)
E/AndroidRuntime( 1393): at android.app.Activity.startActivity(Activity.java:2923)
E/AndroidRuntime( 1393): at org.openintents.distribution.EulaOrNewVersion.startForwardActivity(EulaOrNewVersion.java:127)
E/AndroidRuntime( 1393): at org.openintents.distribution.EulaOrNewVersion.showEula(EulaOrNewVersion.java:69)
E/AndroidRuntime( 1393): at org.openintents.distribution.DistributionLibrary.showEulaOrNewVersion(DistributionLibrary.java:53)
E/AndroidRuntime( 1393): at org.openintents.filemanager.FileManagerActivity.onCreate(FileManagerActivity.java:312)
E/AndroidRuntime( 1393): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime( 1393): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
E/AndroidRuntime( 1393): ... 11 more
W/ActivityManager( 59): Force finishing activity com.androidcoretest/org.openintents.filemanager.FileManagerActivity
I would say this is a bug of Eclipse. Eclipse and ADT recently have many bugs on building process: ClassNotFound and ActivityNotFound.
Update:
My code just use one line:
final Intent intent = new Intent(FileExplorerTest.this, FileManagerActivity.class);
startActivity(intent);
Actually I have 3 projects. 2 library projects and 1 test project. Library "OI File Manager" uses Library "OI Distribution", then the test project C uses library "IO File Manager".
Ensure you are linking the OI FileManager projects as a library rather than external jar. go to Project properties > Android > Library, then click add library.
Then as you are doing define the activity in your project manifest (however with ADT 20 i think this is automatic)
<activity
android:label="#string/app_name"
android:name="org.openintents.filemanager.FileManagerActivity" >
</activity>
I guess it can't find com.androidcoretest/org.openintents.distribution.EulaActivity not the FileManager activity. Do you have that EulaActivity in the manifest?
See in your log:
Caused by: android.content.ActivityNotFoundException: Unable to find
explicit activity class
{com.androidcoretest/org.openintents.distribution.EulaActivity}; have
you declared this activity in your AndroidManifest.xml?

java.lang.RuntimeException: system server dead?

My appwidget crashes with following error:
E/AndroidRuntime( 5572): FATAL EXCEPTION: main
E/AndroidRuntime( 5572): java.lang.RuntimeException: Unable to start receiver com.android.mlweatherwidget.WeatherWidgetLarge: java.lang.RuntimeException: system server dead?
E/AndroidRuntime( 5572): at android.app.ActivityThread.handleReceiver(ActivityThread.java:1805)
E/AndroidRuntime( 5572): at android.app.ActivityThread.access$2400(ActivityThread.java:117)
E/AndroidRuntime( 5572): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:981)
E/AndroidRuntime( 5572): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 5572): at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime( 5572): at android.app.ActivityThread.main(ActivityThread.java:3683)
E/AndroidRuntime( 5572): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 5572): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 5572): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime( 5572): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime( 5572): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 5572): Caused by: java.lang.RuntimeException: system server dead?
E/AndroidRuntime( 5572): at com.android.mlhome.appwidget.AppWidgetManager.getAppWidgetIds(AppWidgetManager.java:375)
E/AndroidRuntime( 5572): at com.android.mlweatherwidget.WeatherWidgetLarge.onReceive(WeatherWidgetLarge.java:202)
E/AndroidRuntime( 5572): at android.app.ActivityThread.handleReceiver(ActivityThread.java:1794)
E/AndroidRuntime( 5572): ... 10 more
E/AndroidRuntime( 5572): Caused by: android.os.DeadObjectException
E/AndroidRuntime( 5572): at android.os.BinderProxy.transact(Native Method)
E/AndroidRuntime( 5572): at com.android.mlhome.appwidget.ILauncherAppWidget$Stub$Proxy.getAppWidgetIds(ILauncherAppWidget.java:256)
E/AndroidRuntime( 5572): at com.android.mlhome.appwidget.AppWidgetManager.getAppWidgetIds(AppWidgetManager.java:369)
E/AndroidRuntime( 5572): ... 12 more
Can anybody understand from the above log what exactly is causing this error?
How to fix android.os.DeadObjectException android X
this guy met the same issue, check this link out.
I copyed the answer written by Dimitar Dimitrov as follows
This means that your service had already stopped - either killed from
the OS, or stopped from your application.
Does this problem happen every time you debug your project?
Override your service's onDestroy() method and watch what event flow
leads to it. If you catch DeadObjectException without going through
this method, your service should have been killed by the OS.

Categories

Resources