Cannot initialize a valid AudioRecord - android

I am trying to instantiate an AudioRecord in order to monitor the audio in real time, but it fails even though I try multiple different configurations.
I've tried restarting my phone multiple times, and I have
<uses-permission android:name="android.permission.RECORD_AUDIO" />
in my manifest (in the <manifest> tag, not in the <application> tag).
The solutions I've found for this problem have been to make sure the permission is correct and is in the right place (check), to make sure to call release() on all AudioRecord instances (check), to restart the phone (check) and to use a method of finding a valid combination of sample rate, audio format and channel configuration (check).
I've tried this on a Samsung Galaxy S5 running Android 4.4.2 and a Motorola Moto G running Android 4.4.4 by the way.
Here's my code for trying to find a valid AudioRecord:
public AudioRecord findAudioRecord() {
int[] mSampleRates = new int[] { 44100, 11025, 22050, 16000, 8000 };
short [] aformats = new short[] { AudioFormat.ENCODING_PCM_16BIT, AudioFormat.ENCODING_PCM_8BIT };
short [] chConfigs = new short[] { AudioFormat.CHANNEL_IN_MONO, AudioFormat.CHANNEL_IN_STEREO };
for (int rate : mSampleRates) {
for (short audioFormat : aformats) {
for (short channelConfig : chConfigs) {
try {
Log.d("SoundMeter", "Attempting rate " + rate + "Hz, bits: " + audioFormat + ", channel: " + channelConfig);
int bufferSize = AudioRecord.getMinBufferSize(rate, channelConfig, audioFormat);
if (bufferSize != AudioRecord.ERROR_BAD_VALUE) {
Log.d("SoundMeter", "Buffer size OK");
// Try to instantiate
AudioRecord recorder = new AudioRecord(android.media.MediaRecorder.AudioSource.MIC, rate, channelConfig, audioFormat, java.lang.Math.max(bufferSize,1024*800));
if( recorder.getState() == AudioRecord.STATE_INITIALIZED ){
Log.d("SoundMeter", "Success: AudioRecord initialized!");
return recorder;
}
else {
Log.d("SoundMeter", "Failed: AudioRecord not initialized");
// Important! Release recorder
recorder.release();
}
}
}
catch (Exception e) {
Log.e("SoundMeter", "Exception on sample rate " + rate + "\n ", e);
}
}
}
}
Log.println(Log.ASSERT, "SoundMeter", "No valid audio record configuration found!");
return null;
}
And here's the logcat from running the above method:
05-20 11:42:34.146 8326-8326/com.my.app D/SoundMeter: Attempting rate 44100Hz, bits: 2, channel: 16
05-20 11:42:34.156 8326-8326/com.my.app D/SoundMeter: Buffer size OK
05-20 11:42:34.196 8326-8326/com.my.app E/AudioRecord: AudioFlinger could not create record track, status: -12
05-20 11:42:34.196 8326-8326/com.my.app E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed.
05-20 11:42:34.196 8326-8326/com.my.app E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
05-20 11:42:34.196 8326-8326/com.my.app D/SoundMeter: Failed: AudioRecord not initialized
05-20 11:42:34.196 8326-8326/com.my.app D/SoundMeter: Attempting rate 44100Hz, bits: 2, channel: 12
05-20 11:42:34.196 8326-8326/com.my.app D/SoundMeter: Buffer size OK
05-20 11:42:34.196 8326-8326/com.my.app E/AudioRecord: AudioFlinger could not create record track, status: -12
05-20 11:42:34.206 8326-8326/com.my.app E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed.
05-20 11:42:34.206 8326-8326/com.my.app E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
05-20 11:42:34.206 8326-8326/com.my.app D/SoundMeter: Failed: AudioRecord not initialized
05-20 11:42:34.206 8326-8326/com.my.app D/SoundMeter: Attempting rate 44100Hz, bits: 3, channel: 16
05-20 11:42:34.206 8326-8326/com.my.app E/android.media.AudioRecord: getMinBufferSize(): Invalid audio format.
05-20 11:42:34.206 8326-8326/com.my.app D/SoundMeter: Attempting rate 44100Hz, bits: 3, channel: 12
05-20 11:42:34.206 8326-8326/com.my.app E/android.media.AudioRecord: getMinBufferSize(): Invalid audio format.
05-20 11:42:34.206 8326-8326/com.my.app D/SoundMeter: Attempting rate 11025Hz, bits: 2, channel: 16
05-20 11:42:34.206 8326-8326/com.my.app D/SoundMeter: Buffer size OK
05-20 11:42:34.206 8326-8326/com.my.app E/AudioRecord: AudioFlinger could not create record track, status: -12
05-20 11:42:34.206 8326-8326/com.my.app E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed.
05-20 11:42:34.206 8326-8326/com.my.app E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
05-20 11:42:34.206 8326-8326/com.my.app D/SoundMeter: Failed: AudioRecord not initialized
05-20 11:42:34.206 8326-8326/com.my.app D/SoundMeter: Attempting rate 11025Hz, bits: 2, channel: 12
05-20 11:42:34.206 8326-8326/com.my.app D/SoundMeter: Buffer size OK
05-20 11:42:34.216 8326-8326/com.my.app E/AudioRecord: AudioFlinger could not create record track, status: -12
05-20 11:42:34.216 8326-8326/com.my.app E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed.
05-20 11:42:34.216 8326-8326/com.my.app E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
05-20 11:42:34.216 8326-8326/com.my.app D/SoundMeter: Failed: AudioRecord not initialized
05-20 11:42:34.216 8326-8326/com.my.app D/SoundMeter: Attempting rate 11025Hz, bits: 3, channel: 16
05-20 11:42:34.216 8326-8326/com.my.app E/android.media.AudioRecord: getMinBufferSize(): Invalid audio format.
05-20 11:42:34.216 8326-8326/com.my.app D/SoundMeter: Attempting rate 11025Hz, bits: 3, channel: 12
05-20 11:42:34.216 8326-8326/com.my.app E/android.media.AudioRecord: getMinBufferSize(): Invalid audio format.
05-20 11:42:34.216 8326-8326/com.my.app D/SoundMeter: Attempting rate 22050Hz, bits: 2, channel: 16
05-20 11:42:34.216 8326-8326/com.my.app D/SoundMeter: Buffer size OK
05-20 11:42:34.216 8326-8326/com.my.app E/AudioRecord: AudioFlinger could not create record track, status: -12
05-20 11:42:34.216 8326-8326/com.my.app E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed.
05-20 11:42:34.216 8326-8326/com.my.app E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
05-20 11:42:34.216 8326-8326/com.my.app D/SoundMeter: Failed: AudioRecord not initialized
05-20 11:42:34.216 8326-8326/com.my.app D/SoundMeter: Attempting rate 22050Hz, bits: 2, channel: 12
05-20 11:42:34.226 8326-8326/com.my.app D/SoundMeter: Buffer size OK
05-20 11:42:34.226 8326-8326/com.my.app E/AudioRecord: AudioFlinger could not create record track, status: -12
05-20 11:42:34.226 8326-8326/com.my.app E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed.
05-20 11:42:34.226 8326-8326/com.my.app E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
05-20 11:42:34.226 8326-8326/com.my.app D/SoundMeter: Failed: AudioRecord not initialized
05-20 11:42:34.226 8326-8326/com.my.app D/SoundMeter: Attempting rate 22050Hz, bits: 3, channel: 16
05-20 11:42:34.226 8326-8326/com.my.app E/android.media.AudioRecord: getMinBufferSize(): Invalid audio format.
05-20 11:42:34.226 8326-8326/com.my.app D/SoundMeter: Attempting rate 22050Hz, bits: 3, channel: 12
05-20 11:42:34.226 8326-8326/com.my.app E/android.media.AudioRecord: getMinBufferSize(): Invalid audio format.
05-20 11:42:34.226 8326-8326/com.my.app D/SoundMeter: Attempting rate 16000Hz, bits: 2, channel: 16
05-20 11:42:34.226 8326-8326/com.my.app D/SoundMeter: Buffer size OK
05-20 11:42:34.226 8326-8326/com.my.app E/AudioRecord: AudioFlinger could not create record track, status: -12
05-20 11:42:34.236 8326-8326/com.my.app E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed.
05-20 11:42:34.236 8326-8326/com.my.app E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
05-20 11:42:34.236 8326-8326/com.my.app D/SoundMeter: Failed: AudioRecord not initialized
05-20 11:42:34.236 8326-8326/com.my.app D/SoundMeter: Attempting rate 16000Hz, bits: 2, channel: 12
05-20 11:42:34.236 8326-8326/com.my.app D/SoundMeter: Buffer size OK
05-20 11:42:34.236 8326-8326/com.my.app E/AudioRecord: AudioFlinger could not create record track, status: -12
05-20 11:42:34.236 8326-8326/com.my.app E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed.
05-20 11:42:34.236 8326-8326/com.my.app E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
05-20 11:42:34.236 8326-8326/com.my.app D/SoundMeter: Failed: AudioRecord not initialized
05-20 11:42:34.236 8326-8326/com.my.app D/SoundMeter: Attempting rate 16000Hz, bits: 3, channel: 16
05-20 11:42:34.236 8326-8326/com.my.app E/android.media.AudioRecord: getMinBufferSize(): Invalid audio format.
05-20 11:42:34.236 8326-8326/com.my.app D/SoundMeter: Attempting rate 16000Hz, bits: 3, channel: 12
05-20 11:42:34.236 8326-8326/com.my.app E/android.media.AudioRecord: getMinBufferSize(): Invalid audio format.
05-20 11:42:34.236 8326-8326/com.my.app D/SoundMeter: Attempting rate 8000Hz, bits: 2, channel: 16
05-20 11:42:34.236 8326-8326/com.my.app D/SoundMeter: Buffer size OK
05-20 11:42:34.246 8326-8326/com.my.app E/AudioRecord: AudioFlinger could not create record track, status: -12
05-20 11:42:34.246 8326-8326/com.my.app E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed.
05-20 11:42:34.246 8326-8326/com.my.app E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
05-20 11:42:34.246 8326-8326/com.my.app D/SoundMeter: Failed: AudioRecord not initialized
05-20 11:42:34.246 8326-8326/com.my.app D/SoundMeter: Attempting rate 8000Hz, bits: 2, channel: 12
05-20 11:42:34.246 8326-8326/com.my.app D/SoundMeter: Buffer size OK
05-20 11:42:34.246 8326-8326/com.my.app E/AudioRecord: AudioFlinger could not create record track, status: -12
05-20 11:42:34.256 8326-8326/com.my.app E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed.
05-20 11:42:34.256 8326-8326/com.my.app E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
05-20 11:42:34.256 8326-8326/com.my.app D/SoundMeter: Failed: AudioRecord not initialized
05-20 11:42:34.256 8326-8326/com.my.app D/SoundMeter: Attempting rate 8000Hz, bits: 3, channel: 16
05-20 11:42:34.256 8326-8326/com.my.app E/android.media.AudioRecord: getMinBufferSize(): Invalid audio format.
05-20 11:42:34.256 8326-8326/com.my.app D/SoundMeter: Attempting rate 8000Hz, bits: 3, channel: 12
05-20 11:42:34.256 8326-8326/com.my.app E/android.media.AudioRecord: getMinBufferSize(): Invalid audio format.
05-20 11:42:34.256 8326-8326/com.my.app A/SoundMeter: No valid audio record configuration found!

Check this post for reference, It says AudioRecord.getMinBufferSize does not support PCM_8BIT
AudioRecord - Invalid audio buffer size
Hope this may help you.

Related

Kotlin Android error messages, but app runs well

My Android app written in Kotlin is ok to run, but Android Studio keeps showing a lot of errors. Can anyone help me solve it?
06-12 20:30:40.244 1500-11361/? E/AudioFlinger: not enough memory for AudioTrack size=131296
06-12 20:30:40.244 1500-11361/? E/AudioFlinger: createRecordTrack_l() initCheck failed -12; no control block?
06-12 20:30:40.244 2960-13595/com.google.android.googlequicksearchbox:search E/AudioRecord: AudioFlinger could not create record track, status: -12
06-12 20:30:40.246 2960-13595/com.google.android.googlequicksearchbox:search E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -12.
06-12 20:30:40.246 2960-13595/com.google.android.googlequicksearchbox:search E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
06-12 20:30:45.283 1500-1808/? E/AudioFlinger: not enough memory for AudioTrack size=131296
06-12 20:30:45.284 1500-1808/? E/AudioFlinger: createRecordTrack_l() initCheck failed -12; no control block?
06-12 20:30:45.284 2960-13595/com.google.android.googlequicksearchbox:search E/AudioRecord: AudioFlinger could not create record track, status: -12
06-12 20:30:45.285 2960-13595/com.google.android.googlequicksearchbox:search E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -12.
06-12 20:30:45.285 2960-13595/com.google.android.googlequicksearchbox:search E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
06-12 20:30:50.312 1500-1808/? E/AudioFlinger: not enough memory for AudioTrack size=131296
06-12 20:30:50.312 1500-1808/? E/AudioFlinger: createRecordTrack_l() initCheck failed -12; no control block?
06-12 20:30:50.312 2960-13595/com.google.android.googlequicksearchbox:search E/AudioRecord: AudioFlinger could not create record track, status: -12
06-12 20:30:50.314 2960-13595/com.google.android.googlequicksearchbox:search E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -12.
06-12 20:30:50.314 2960-13595/com.google.android.googlequicksearchbox:search E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
06-12 20:30:55.347 1500-1808/? E/AudioFlinger: not enough memory for AudioTrack size=131296
06-12 20:30:55.347 1500-1808/? E/AudioFlinger: createRecordTrack_l() initCheck failed -12; no control block?
06-12 20:30:55.348 2960-13595/com.google.android.googlequicksearchbox:search E/AudioRecord: AudioFlinger could not create record track, status: -12
06-12 20:30:55.349 2960-13595/com.google.android.googlequicksearchbox:search E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -12.
06-12 20:30:55.349 2960-13595/com.google.android.googlequicksearchbox:search E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
06-12 20:31:00.009 1664-1684/system_process E/memtrack: Couldn't load memtrack module

How to debug in Android Studio Logcat

I am new to Android Studio and Android programming and am attempting to follow a how to lesson. I am having a lot of trouble following Android Studio Logcat because it is not as straightforward to me as any IDEs have used. Could someone please decode what things mean in my errors? I need to learn how to use Logcat since the explanations I see online are too simplified and do not cover much.
What exactly is:"2359-13990/"?
How do I find the place in the code that caused the errors?
What exactly does my error output from Logcat mean?
Due to the space limit, I have changed my post and now have only errors instead of verbose. Here are my errors in Logcat:
06-21 21:11:46.347 2359-13990/com.google.android.googlequicksearchbox:search E/AudioRecord: Could not get audio input for session 3105, record source 1999, sample rate 16000, format 0x1, channel mask 0x10, flags 0
06-21 21:11:46.348 2359-13990/com.google.android.googlequicksearchbox:search E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -22.
06-21 21:11:46.348 2359-13990/com.google.android.googlequicksearchbox:search E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
06-21 21:11:46.349 2359-13990/com.google.android.googlequicksearchbox:search E/ActivityThread: Failed to find provider info for com.google.android.apps.gsa.testing.ui.audio.recorded
06-21 21:11:47.142 29992-29992/? E/cutils-trace: Error opening trace file: Permission denied (13)
06-21 21:11:47.185 29992-29992/? E/memtrack: Couldn't load memtrack module (No such file or directory)
06-21 21:11:47.185 29992-29992/? E/android.os.Debug: failed to load memtrack module: -2
06-21 21:11:47.398 30006-30006/? E/cutils-trace: Error opening trace file: Permission denied (13)
06-21 21:11:47.440 30006-30006/? E/memtrack: Couldn't load memtrack module (No such file or directory)
06-21 21:11:47.440 30006-30006/? E/android.os.Debug: failed to load memtrack module: -2
06-21 21:11:47.770 30029-30029/? E/cutils-trace: Error opening trace file: Permission denied (13)
06-21 21:11:47.811 30029-30029/? E/memtrack: Couldn't load memtrack module (No such file or directory)
06-21 21:11:47.812 30029-30029/? E/android.os.Debug: failed to load memtrack module: -2
06-21 21:11:49.172 30041-30041/? E/cutils-trace: Error opening trace file: Permission denied (13)
06-21 21:11:49.227 30046-30046/? E/cutils-trace: Error opening trace file: Permission denied (13)
06-21 21:11:49.229 30041-30041/? E/memtrack: Couldn't load memtrack module (No such file or directory)
06-21 21:11:49.229 30041-30041/? E/android.os.Debug: failed to load memtrack module: -2
06-21 21:11:49.279 30046-30046/? E/memtrack: Couldn't load memtrack module (No such file or directory)
06-21 21:11:49.279 30046-30046/? E/android.os.Debug: failed to load memtrack module: -2
06-21 21:11:49.331 30063-30070/? E/art: Failed sending reply to debugger: Broken pipe
06-21 21:11:52.997 30063-30063/com.example.android.sunshine E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.sunshine, PID: 30063
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.sunshine/com.example.android.sunshine.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ProgressBar.setVisibility(int)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ProgressBar.setVisibility(int)' on a null object reference
at com.example.android.sunshine.MainActivity$FetchWeatherTask.onPreExecute(MainActivity.java:97)
at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:620)
at android.os.AsyncTask.execute(AsyncTask.java:567)
at com.example.android.sunshine.MainActivity.loadWeatherData(MainActivity.java:74)
at com.example.android.sunshine.MainActivity.onCreate(MainActivity.java:63)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6119) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 
06-21 21:11:53.668 2359-13990/com.google.android.googlequicksearchbox:search E/AudioRecord: Could not get audio input for session 3113, record source 1999, sample rate 16000, format 0x1, channel mask 0x10, flags 0
06-21 21:11:53.669 2359-13990/com.google.android.googlequicksearchbox:search E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -22.
06-21 21:11:53.669 2359-13990/com.google.android.googlequicksearchbox:search E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
06-21 21:11:53.669 2359-13990/com.google.android.googlequicksearchbox:search E/ActivityThread: Failed to find provider info for com.google.android.apps.gsa.testing.ui.audio.recorded
06-21 21:11:58.689 2359-13990/com.google.android.googlequicksearchbox:search E/AudioRecord: Could not get audio input for session 3121, record source 1999, sample rate 16000, format 0x1, channel mask 0x10, flags 0
06-21 21:11:58.689 2359-13990/com.google.android.googlequicksearchbox:search E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -22.
06-21 21:11:58.689 2359-13990/com.google.android.googlequicksearchbox:search E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
06-21 21:11:58.690 2359-13990/com.google.android.googlequicksearchbox:search E/ActivityThread: Failed to find provider info for com.google.android.apps.gsa.testing.ui.audio.recorded
06-21 21:12:03.709 2359-13990/com.google.android.googlequicksearchbox:search E/AudioRecord: Could not get audio input for session 3129, record source 1999, sample rate 16000, format 0x1, channel mask 0x10, flags 0
06-21 21:12:03.711 2359-13990/com.google.android.googlequicksearchbox:search E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -22.
06-21 21:12:03.712 2359-13990/com.google.android.googlequicksearchbox:search E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
06-21 21:12:03.712 2359-13990/com.google.android.googlequicksearchbox:search E/ActivityThread: Failed to find provider info for com.google.android.apps.gsa.testing.ui.audio.recorded
06-21 21:12:08.742 2359-13990/com.google.android.googlequicksearchbox:search E/AudioRecord: Could not get audio input for session 3137, record source 1999, sample rate 16000, format 0x1, channel mask 0x10, flags 0
06-21 21:12:08.742 2359-13990/com.google.android.googlequicksearchbox:search E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -22.
06-21 21:12:08.742 2359-13990/com.google.android.googlequicksearchbox:search E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
06-21 21:12:08.742 2359-13990/com.google.android.googlequicksearchbox:search E/ActivityThread: Failed to find provider info for com.google.android.apps.gsa.testing.ui.audio.recorded
06-21 21:12:13.764 2359-13990/com.google.android.googlequicksearchbox:search E/AudioRecord: Could not get audio input for session 3145, record source 1999, sample rate 16000, format 0x1, channel mask 0x10, flags 0
06-21 21:12:13.764 2359-13990/com.google.android.googlequicksearchbox:search E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -22.
06-21 21:12:13.765 2359-13990/com.google.android.googlequicksearchbox:search E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
06-21 21:12:13.765 2359-13990/com.google.android.googlequicksearchbox:search E/ActivityThread: Failed to find provider info for com.google.android.apps.gsa.testing.ui.audio.recorded
06-21 21:12:18.790 2359-13990/com.google.android.googlequicksearchbox:search E/AudioRecord: Could not get audio input for session 3153, record source 1999, sample rate 16000, format 0x1, channel mask 0x10, flags 0
06-21 21:12:18.790 2359-13990/com.google.android.googlequicksearchbox:search E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -22.
06-21 21:12:18.790 2359-13990/com.google.android.googlequicksearchbox:search E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
06-21 21:12:18.791 2359-13990/com.google.android.googlequicksearchbox:search E/ActivityThread: Failed to find provider info for com.google.android.apps.gsa.testing.ui.audio.recorded
06-21 21:12:23.808 2359-13990/com.google.android.googlequicksearchbox:search E/AudioRecord: Could not get audio input for session 3161, record source 1999, sample rate 16000, format 0x1, channel mask 0x10, flags 0
06-21 21:12:23.808 2359-13990/com.google.android.googlequicksearchbox:search E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -22.
06-21 21:12:23.808 2359-13990/com.google.android.googlequicksearchbox:search E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
06-21 21:12:23.808 2359-13990/com.google.android.googlequicksearchbox:search E/ActivityThread: Failed to find provider info for com.google.android.apps.gsa.testing.ui.audio.recorded
You look for your package name (if you have not selected your project in the dropdown for logging). In you case I suppose its "com.example.android.sunshine".
Just after your package name you will find the exception and more details.
ComponentInfo{com.example.android.sunshine/com.example.android.sunshine.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void'
Below that you can find stacktrace. In that stacktrace again find your package name and you will find exact line where error occurred.
com.example.android.sunshine.MainActivity$FetchWeatherTask.onPreExecute(MainActivity.java:97)

Android - Failed to Initialize an AudioRecord for All Possible Combinations of Arguments

I'm using the code below find an available combination of params to create an AudioRecord object.
public static AudioRecord findAudioRecord() {
for (int rate : new int[]{8000, 11025, 16000, 22050, 44100}) {
for (int audioFormat : new int[]{
AudioFormat.ENCODING_DEFAULT,
AudioFormat.ENCODING_PCM_16BIT,
AudioFormat.ENCODING_PCM_8BIT,
AudioFormat.ENCODING_PCM_FLOAT,
AudioFormat.ENCODING_AC3,
AudioFormat.ENCODING_E_AC3,
AudioFormat.ENCODING_DTS,
AudioFormat.ENCODING_DTS_HD,
}) {
for (int channelConfig : new int[]{
AudioFormat.CHANNEL_IN_DEFAULT,
AudioFormat.CHANNEL_IN_LEFT,
AudioFormat.CHANNEL_IN_RIGHT,
AudioFormat.CHANNEL_IN_FRONT,
AudioFormat.CHANNEL_IN_BACK,
AudioFormat.CHANNEL_IN_LEFT_PROCESSED,
AudioFormat.CHANNEL_IN_RIGHT_PROCESSED,
AudioFormat.CHANNEL_IN_FRONT_PROCESSED,
AudioFormat.CHANNEL_IN_BACK_PROCESSED,
AudioFormat.CHANNEL_IN_PRESSURE,
AudioFormat.CHANNEL_IN_X_AXIS,
AudioFormat.CHANNEL_IN_Y_AXIS,
AudioFormat.CHANNEL_IN_Z_AXIS,
AudioFormat.CHANNEL_IN_VOICE_UPLINK,
AudioFormat.CHANNEL_IN_VOICE_DNLINK,
AudioFormat.CHANNEL_IN_MONO,
AudioFormat.CHANNEL_IN_STEREO}) {
try {
Log.d(TAG, "Attempting rate " + rate + "Hz, bits: " + audioFormat + ", channel: "
+ channelConfig);
int bufferSize = AudioRecord.getMinBufferSize(rate, channelConfig, audioFormat);
if (bufferSize != AudioRecord.ERROR_BAD_VALUE) {
// check if we can instantiate and have a success
AudioRecord recorder = new AudioRecord(MediaRecorder.AudioSource.DEFAULT, rate, channelConfig, audioFormat, bufferSize);
if (recorder.getState() == AudioRecord.STATE_INITIALIZED) {
return recorder;
}
recorder.release();
}
} catch (Exception e) {
Log.e(TAG, rate + "Exception, keep trying.", e);
}
}
}
}
return null;
}
But the function always returns null, with no available params found. Most combinations pass the bufferSize != AudioRecord.ERROR_BAD_VALUE condition check, but get false for recorder.getState() == AudioRecord.STATE_INITIALIZED.
I have tried to reboot my device (MOTO X2), but it didn't work.
I have declared the RECORD_AUDIO permission, and below is the manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gowear">
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".RecordActivity"
android:label="#string/title_activity_record"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
Below is the debug log:
03-08 20:48:58.080 12250-12250/com.example.gowear D/Recorder: Attempting rate 8000Hz, bits: 3, channel: 16
03-08 20:48:58.091 12250-12250/com.example.gowear E/AudioRecord: AudioFlinger could not create record track, status: -1
03-08 20:48:58.092 12250-12250/com.example.gowear E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -1.
03-08 20:48:58.092 12250-12250/com.example.gowear E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
03-08 20:48:58.093 12250-12250/com.example.gowear D/Recorder: Attempting rate 8000Hz, bits: 3, channel: 12
03-08 20:48:58.096 12250-12250/com.example.gowear E/AudioRecord: AudioFlinger could not create record track, status: -1
03-08 20:48:58.097 12250-12250/com.example.gowear E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -1.
03-08 20:48:58.097 12250-12250/com.example.gowear E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
03-08 20:48:58.097 12250-12250/com.example.gowear D/Recorder: Attempting rate 8000Hz, bits: 3, channel: 1
03-08 20:48:58.101 12250-12250/com.example.gowear E/AudioRecord: AudioFlinger could not create record track, status: -1
03-08 20:48:58.102 12250-12250/com.example.gowear E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -1.
03-08 20:48:58.102 12250-12250/com.example.gowear E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
03-08 20:48:58.102 12250-12250/com.example.gowear D/Recorder: Attempting rate 8000Hz, bits: 2, channel: 16
03-08 20:48:58.105 12250-12250/com.example.gowear E/AudioRecord: AudioFlinger could not create record track, status: -1
03-08 20:48:58.106 12250-12250/com.example.gowear E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -1.
03-08 20:48:58.106 12250-12250/com.example.gowear E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
03-08 20:48:58.106 12250-12250/com.example.gowear D/Recorder: Attempting rate 8000Hz, bits: 2, channel: 12
03-08 20:48:58.109 12250-12250/com.example.gowear E/AudioRecord: AudioFlinger could not create record track, status: -1
03-08 20:48:58.110 12250-12250/com.example.gowear E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -1.
03-08 20:48:58.110 12250-12250/com.example.gowear E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
03-08 20:48:58.110 12250-12250/com.example.gowear D/Recorder: Attempting rate 8000Hz, bits: 2, channel: 1
03-08 20:48:58.114 12250-12250/com.example.gowear E/AudioRecord: AudioFlinger could not create record track, status: -1
03-08 20:48:58.115 12250-12250/com.example.gowear E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -1.
03-08 20:48:58.115 12250-12250/com.example.gowear E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
03-08 20:48:58.115 12250-12250/com.example.gowear D/Recorder: Attempting rate 8000Hz, bits: 1, channel: 16
03-08 20:48:58.115 12250-12250/com.example.gowear E/AudioSystem: AudioSystem::getInputBufferSize failed sampleRate 8000 format 0 channelMask 10
03-08 20:48:58.115 12250-12250/com.example.gowear E/AudioRecord: AudioSystem could not query the input buffer size for sampleRate 8000, format 0, channelMask 0x10; status -22
03-08 20:48:58.115 12250-12250/com.example.gowear D/Recorder: Attempting rate 8000Hz, bits: 1, channel: 12
03-08 20:48:58.116 12250-12250/com.example.gowear E/AudioSystem: AudioSystem::getInputBufferSize failed sampleRate 8000 format 0 channelMask c
03-08 20:48:58.116 12250-12250/com.example.gowear E/AudioRecord: AudioSystem could not query the input buffer size for sampleRate 8000, format 0, channelMask 0xc; status -22
03-08 20:48:58.116 12250-12250/com.example.gowear D/Recorder: Attempting rate 8000Hz, bits: 1, channel: 1
03-08 20:48:58.116 12250-12250/com.example.gowear E/AudioSystem: AudioSystem::getInputBufferSize failed sampleRate 8000 format 0 channelMask 10
03-08 20:48:58.116 12250-12250/com.example.gowear E/AudioRecord: AudioSystem could not query the input buffer size for sampleRate 8000, format 0, channelMask 0x10; status -22
03-08 20:48:58.116 12250-12250/com.example.gowear D/Recorder: Attempting rate 8000Hz, bits: 5, channel: 16
03-08 20:48:58.116 12250-12250/com.example.gowear E/AudioSystem: AudioSystem::getInputBufferSize failed sampleRate 8000 format 0x9000000 channelMask 10
03-08 20:48:58.116 12250-12250/com.example.gowear E/AudioRecord: AudioSystem could not query the input buffer size for sampleRate 8000, format 0x9000000, channelMask 0x10; status -22
03-08 20:48:58.116 12250-12250/com.example.gowear D/Recorder: Attempting rate 8000Hz, bits: 5, channel: 12
03-08 20:48:58.116 12250-12250/com.example.gowear E/AudioSystem: AudioSystem::getInputBufferSize failed sampleRate 8000 format 0x9000000 channelMask c
03-08 20:48:58.116 12250-12250/com.example.gowear E/AudioRecord: AudioSystem could not query the input buffer size for sampleRate 8000, format 0x9000000, channelMask 0xc; status -22
03-08 20:48:58.117 12250-12250/com.example.gowear D/Recorder: Attempting rate 8000Hz, bits: 5, channel: 1
03-08 20:48:58.117 12250-12250/com.example.gowear E/AudioSystem: AudioSystem::getInputBufferSize failed sampleRate 8000 format 0x9000000 channelMask 10
03-08 20:48:58.117 12250-12250/com.example.gowear E/AudioRecord: AudioSystem could not query the input buffer size for sampleRate 8000, format 0x9000000, channelMask 0x10; status -22
03-08 20:48:58.117 12250-12250/com.example.gowear D/Recorder: Attempting rate 8000Hz, bits: 6, channel: 16
03-08 20:48:58.117 12250-12250/com.example.gowear E/AudioSystem: AudioSystem::getInputBufferSize failed sampleRate 8000 format 0xa000000 channelMask 10
03-08 20:48:58.117 12250-12250/com.example.gowear E/AudioRecord: AudioSystem could not query the input buffer size for sampleRate 8000, format 0xa000000, channelMask 0x10; status -22
03-08 20:48:58.117 12250-12250/com.example.gowear D/Recorder: Attempting rate 8000Hz, bits: 6, channel: 12
03-08 20:48:58.117 12250-12250/com.example.gowear E/AudioSystem: AudioSystem::getInputBufferSize failed sampleRate 8000 format 0xa000000 channelMask c
03-08 20:48:58.117 12250-12250/com.example.gowear E/AudioRecord: AudioSystem could not query the input buffer size for sampleRate 8000, format 0xa000000, channelMask 0xc; status -22
03-08 20:48:58.118 12250-12250/com.example.gowear D/Recorder: Attempting rate 8000Hz, bits: 6, channel: 1
03-08 20:48:58.118 12250-12250/com.example.gowear E/AudioSystem: AudioSystem::getInputBufferSize failed sampleRate 8000 format 0xa000000 channelMask 10
03-08 20:48:58.118 12250-12250/com.example.gowear E/AudioRecord: AudioSystem could not query the input buffer size for sampleRate 8000, format 0xa000000, channelMask 0x10; status -22
03-08 20:48:58.118 12250-12250/com.example.gowear D/Recorder: Attempting rate 8000Hz, bits: 4, channel: 16
03-08 20:48:58.121 12250-12250/com.example.gowear E/AudioRecord: AudioFlinger could not create record track, status: -1
03-08 20:48:58.123 12250-12250/com.example.gowear E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -1.
03-08 20:48:58.123 12250-12250/com.example.gowear E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
03-08 20:48:58.123 12250-12250/com.example.gowear D/Recorder: Attempting rate 8000Hz, bits: 4, channel: 12
03-08 20:48:58.126 12250-12250/com.example.gowear E/AudioRecord: AudioFlinger could not create record track, status: -1
03-08 20:48:58.127 12250-12250/com.example.gowear E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -1.
03-08 20:48:58.127 12250-12250/com.example.gowear E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
03-08 20:48:58.127 12250-12250/com.example.gowear D/Recorder: Attempting rate 8000Hz, bits: 4, channel: 1
03-08 20:48:58.133 12250-12250/com.example.gowear E/AudioRecord: AudioFlinger could not create record track, status: -1
03-08 20:48:58.134 12250-12250/com.example.gowear E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -1.
03-08 20:48:58.134 12250-12250/com.example.gowear E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
03-08 20:48:58.134 12250-12250/com.example.gowear D/Recorder: Attempting rate 11025Hz, bits: 3, channel: 16
03-08 20:48:58.137 12250-12250/com.example.gowear E/AudioRecord: AudioFlinger could not create record track, status: -1
03-08 20:48:58.138 12250-12250/com.example.gowear E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -1.
03-08 20:48:58.138 12250-12250/com.example.gowear E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
03-08 20:48:58.139 12250-12250/com.example.gowear D/Recorder: Attempting rate 11025Hz, bits: 3, channel: 12
03-08 20:48:58.141 12250-12250/com.example.gowear E/AudioRecord: AudioFlinger could not create record track, status: -1
03-08 20:48:58.149 12250-12250/com.example.gowear E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -1.
03-08 20:48:58.149 12250-12250/com.example.gowear E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
03-08 20:48:58.149 12250-12250/com.example.gowear D/Recorder: Attempting rate 11025Hz, bits: 3, channel: 1
03-08 20:48:58.152 12250-12250/com.example.gowear E/AudioRecord: AudioFlinger could not create record track, status: -1
03-08 20:48:58.154 12250-12250/com.example.gowear E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -1.
03-08 20:48:58.154 12250-12250/com.example.gowear E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
03-08 20:48:58.154 12250-12250/com.example.gowear D/Recorder: Attempting rate 11025Hz, bits: 2, channel: 16
03-08 20:48:58.157 12250-12250/com.example.gowear E/AudioRecord: AudioFlinger could not create record track, status: -1
03-08 20:48:58.159 12250-12250/com.example.gowear E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -1.
03-08 20:48:58.159 12250-12250/com.example.gowear E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
03-08 20:48:58.159 12250-12250/com.example.gowear D/Recorder: Attempting rate 11025Hz, bits: 2, channel: 12
03-08 20:48:58.161 12250-12250/com.example.gowear E/AudioRecord: AudioFlinger could not create record track, status: -1
03-08 20:48:58.163 12250-12250/com.example.gowear E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -1.
03-08 20:48:58.163 12250-12250/com.example.gowear E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
03-08 20:48:58.163 12250-12250/com.example.gowear D/Recorder: Attempting rate 11025Hz, bits: 2, channel: 1
03-08 20:48:58.166 12250-12250/com.example.gowear E/AudioRecord: AudioFlinger could not create record track, status: -1
03-08 20:48:58.167 12250-12250/com.example.gowear E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -1.
03-08 20:48:58.167 12250-12250/com.example.gowear E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
03-08 20:48:58.167 12250-12250/com.example.gowear D/Recorder: Attempting rate 11025Hz, bits: 1, channel: 16
03-08 20:48:58.168 12250-12250/com.example.gowear E/AudioSystem: AudioSystem::getInputBufferSize failed sampleRate 11025 format 0 channelMask 10
03-08 20:48:58.168 12250-12250/com.example.gowear E/AudioRecord: AudioSystem could not query the input buffer size for sampleRate 11025, format 0, channelMask 0x10; status -22
...
I have read lots of similar questions but none of them could fix my problem. Is there any other solution? Thanks!
I had the same problem so my solution was, if you are using the Marshmallow version there is a new permission system. To allow the permissions in your device do this steps:
Go to "Application manager" as follow "Settings->Applications->Application manager".
Locate your application a select it to get the "Application info".
If the permissions options shows "No permissions allowed" then tap on it to switch on these permissions. This will allow your app to run fine.

Android MediaMuxer failed to stop

I am trying to use MediaCodec,MediaExtractor and MediaMuxer to generate mp4 file. EveryThing seems to work properly but when i call MediaMuxer.stop i'm having an error . The MP4 file is created but i can't play it with a Player.
Here is my logcat:
02-13 10:41:22.420: D/OpenGLRenderer(11768): Enabling debug mode 0
02-13 10:41:22.600: I/OMXClient(11768): Using client-side OMX mux.
02-13 10:41:22.717: E/ACodec(11768): [OMX.TI.DUCATI1.VIDEO.DECODER] storeMetaDataInBuffers failed w/ err -2147483648
02-13 10:41:22.717: I/ACodec(11768): DRC Mode: Port Reconfig Mode
02-13 10:41:22.725: I/MPEG4Writer(11768): limits: 2147483647/0 bytes/us, bit rate: -1 bps and the estimated moov size 3072 bytes
02-13 10:41:22.803: I/MPEG4Writer(11768): setStartTimestampUs: 0
02-13 10:41:22.803: I/MPEG4Writer(11768): Earliest track starting time: 0
02-13 10:41:22.896: W/AHierarchicalStateMachine(11768): Warning message AMessage(what = 'omx ', target = 1) = {
02-13 10:41:22.896: W/AHierarchicalStateMachine(11768): int32_t type = 0
02-13 10:41:22.896: W/AHierarchicalStateMachine(11768): void *node = 0x4d
02-13 10:41:22.896: W/AHierarchicalStateMachine(11768): int32_t event = 3
02-13 10:41:22.896: W/AHierarchicalStateMachine(11768): int32_t data1 = 1
02-13 10:41:22.896: W/AHierarchicalStateMachine(11768): int32_t data2 = 117440527
02-13 10:41:22.896: W/AHierarchicalStateMachine(11768): } unhandled in root state.
02-13 10:41:22.912: I/MPEG4Writer(11768): setStartTimestampUs: 0
02-13 10:41:22.912: D/DecodeActivity(11768): INFO_OUTPUT_BUFFERS_CHANGED
02-13 10:41:22.935: D/DecodeActivity(11768): New format {height=832, what=1869968451, color-format=256, slice-height=832, crop-left=32, width=1408, crop-bottom=743, crop-top=24, mime=video/raw, stride=4096, crop-right=1311}
02-13 10:41:22.959: W/MPEG4Writer(11768): 0-duration samples found: 1
02-13 10:41:22.975: W/MPEG4Writer(11768): 0-duration samples found: 1
02-13 10:41:22.990: I/ActivityManager(11768): Timeline: Activity_idle id: android.os.BinderProxy#41ab6858 time:26420441
02-13 10:41:33.701: D/DecodeActivity(11768): InputBuffer BUFFER_FLAG_END_OF_STREAM
02-13 10:41:33.709: D/DecodeActivity(11768): OutputBuffer BUFFER_FLAG_END_OF_STREAM
02-13 10:41:33.709: E/MPEG4Writer(11768): There are no sync frames for video track
02-13 10:41:33.717: W/MPEG4Writer(11768): 0-duration samples found: 283
02-13 10:41:33.717: I/MPEG4Writer(11768): Received total/0-length (284/0) buffers and encoded 284 frames. - video
02-13 10:41:33.717: D/MPEG4Writer(11768): Stopping Video track
02-13 10:41:33.717: D/MPEG4Writer(11768): Stopping Video track source
02-13 10:41:33.717: D/MPEG4Writer(11768): Video track stopped
02-13 10:41:33.717: D/MPEG4Writer(11768): Stopping Audio track
02-13 10:41:36.076: W/MPEG4Writer(11768): 0-duration samples found: 453
02-13 10:41:36.076: I/MPEG4Writer(11768): Received total/0-length (454/0) buffers and encoded 454 frames. - audio
02-13 10:41:36.271: I/MPEG4Writer(11768): Audio track drift time: 0 us
02-13 10:41:36.271: D/MPEG4Writer(11768): Stopping Audio track source
02-13 10:41:36.271: D/MPEG4Writer(11768): Audio track stopped
02-13 10:41:36.271: D/MPEG4Writer(11768): Duration from tracks range is [0, 0] us
02-13 10:41:36.271: D/MPEG4Writer(11768): Stopping writer thread
02-13 10:41:36.271: D/MPEG4Writer(11768): 0 chunks are written in the last batch
02-13 10:41:36.271: D/MPEG4Writer(11768): Writer thread stopped
02-13 12:28:47.507: E/MediaMuxer(14233): stop() is called in invalid state 3
02-13 10:41:36.271: W/dalvikvm(11768): threadid=11: thread exiting with uncaught exception (group=0x417fbc80)
02-13 10:41:36.271: E/AndroidRuntime(11768): FATAL EXCEPTION: Thread-2394
02-13 10:41:36.271: E/AndroidRuntime(11768): Process: com.test.applyexporter, PID: 11768
02-13 10:41:36.271: E/AndroidRuntime(11768): java.lang.IllegalStateException: Failed to stop the muxer
02-13 10:41:36.271: E/AndroidRuntime(11768): at android.media.MediaMuxer.nativeStop(Native Method)
02-13 10:41:36.271: E/AndroidRuntime(11768): at android.media.MediaMuxer.stop(MediaMuxer.java:226)
02-13 10:41:36.271: E/AndroidRuntime(11768): at com.test.applyexporter.MainActivity$DecoderThread.releaseDecoder(MainActivity.java:266)
02-13 10:41:36.271: E/AndroidRuntime(11768): at com.test.applyexporter.MainActivity$DecoderThread.run(MainActivity.java:113)
02-13 10:41:36.310: I/Process(11768): Sending signal. PID: 11768 SIG: 9
Any clues why the stop fail ?
Note the error:
E/MPEG4Writer(11768): There are no sync frames for video track
The muxed video output must begin with a sync frame (a/k/a key frame, a/k/a I-frame). If you start with a prediction frame, but nothing to predict from, the decoder won't have any idea what to do.
Make sure you are passing all of the MediaCodec.BufferInfo values through to the MediaMuxer -- that's where the flags are. The sync frames will have the BUFFER_FLAG_SYNC_FRAME flag set.
(Update: as of API 21, BUFFER_FLAG_SYNC_FRAME is deprecated in favor of BUFFER_FLAG_KEY_FRAME. Both symbols have the same integer value and same meaning; the change is just part of an effort to adopt consistent terminology in the API.)

play youtube video in android

I am working on an android app and i want to play streaming video from youtube. I read posts like this: How to play YouTube video in my Android application?
I tried with that source:
startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.youtube.com/watch?v=tsDYIgX_gDs")));
i got video in WebView, i can heard sound but no pictures..Also that is not what i want because i want video to start automatically when the activity start, without clicking Button play(because i want also to add some counters,timers.. for other treatments).
Then, i tried whith MediaPlayer:
String FILE_PATH="http://www.youtube.com/watch?v=tsDYIgX_gDs";
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(FILE_PATH);
mp.prepare();
mp.start();
Hopping here having a control on video start by mp.start(); . But i have these errors:
05-20 15:36:36.279: ERROR/HTTPStream(33): recv failed, errno = 11 (Try again)
05-20 15:36:36.808: ERROR/HTTPDataSource(33): HTTP request failed w/ http status 303
05-20 15:36:36.808: ERROR/HTTPDataSource(33): retrying connection failed
05-20 15:36:41.834: ERROR/HTTPStream(33): recv failed, errno = 11 (Try again)
05-20 15:36:48.389: ERROR/HTTPStream(33): recv failed, errno = 11 (Try again)
05-20 15:36:54.913: ERROR/HTTPStream(33): recv failed, errno = 11 (Try again)
05-20 15:36:54.913: ERROR/HTTPStream(33): recv failed, errno = 9 (Bad file number)
05-20 15:36:54.918: ERROR/HTTPStream(33): recv failed, errno = 9 (Bad file number)
05-20 15:36:54.918: ERROR/HTTPStream(33): recv failed, errno = 9 (Bad file number)
05-20 15:36:54.918: ERROR/MediaPlayer(6392): error (1, -2147483648)
05-20 15:36:55.219: ERROR/MediaPlayer(6392): start called in state 0
05-20 15:36:55.219: ERROR/MediaPlayer(6392): error (-38, 0)
05-20 15:36:55.228: ERROR/MediaPlayer(6392): Error (-38,0)
Can someone help plz?
Try changing the Start intent to :
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse(String.format("http://www.youtube.com/v/%s",
url.substring("vnd.youtube:".length(),n)));
For deeper learning try out the following question : This, and This.

Categories

Resources