AudioRecord library and Galaxy S3

Dave Fitzpatrick

Member
Licensed User
Longtime User
I have an app that uses the AudioRecord library to record a wav file. Everything works fine on my HTC Incredible. But when the wav files are recorded on a Galaxy S3, the files cause an error when attempting to playback. I've copied the wav files saved with the Galaxy S3 to a PC and MS MediaPlayer cannot play them either.

the error is:

java.io.IOException: prepare failed: status-0x1

There does not appear to be any problem with MP on the Galaxy, since if I save the wav file on my HTC and transfer it to the Galaxy, the file plays fine on the Galaxy. So I have to conclude that the issue is with building the wav file on the Galaxy. I'm using settings of

AudioSource=AR.A_Src_Mic
SampleRate= 44100
ChannelConfig=AR.Ch_Conf_Mono
NoChnls=1
AudioFormat= AR.AF_PCM_16
BitsPerSample=16

Any ideas?


Dave
 

Dave Fitzpatrick

Member
Licensed User
Longtime User
I used the code I have from an example posted somewhere on this forum. I'll look into alternatives. Would you be able to post a framework of an alternative approach?

BTW: byte peeking at the wav file header for the Galaxy would confirm that the header is never being updated since the 36 byte offset is not being written to the header, and the datasize remains 0.

Thanks,

Dave
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Hi Dave,

Have you confirmed the status of the endedOK flag when recording finishes? and is there an error in the message?

If the data length is not being updated, then it is probably false if it's getting that far.

As Erel suggests, you could write the code without the threading, this was done as I was experimenting with various different setups and trying to manipulate recording data in real time, which needed minimal interruption. For straightforward recording you won't need it.
 
Upvote 0

Dave Fitzpatrick

Member
Licensed User
Longtime User
Steve, I'm not able to do much serious testing on the Galaxy S3 since the of the two people running tests for me, one lives in Florida and the other in Illinois. I live in Ohio.

As for the non-threaded method, would you have a suggested framework to start with?

I do need to be able to interrupt the recording via a button press. Not a pause and resume, but just to stop the recording at the user's selection.

Dave
 
Last edited:
Upvote 0

Dave Fitzpatrick

Member
Licensed User
Longtime User
Here is what I have found in testing with my remote friends.

The following is the sub for ending the Record thread:

Sub Rec_Ended(endedOK As Boolean,Error As String)
Dim fileLen As Int
'Stop recording
AR.Stop
''close file
OutFile.Close
''release resources
AR.release
''reopen file
OutFile.Initialize2(baseDir, "_audio_00.wav", False,True)
''get file length and subtract 44 bytes (header length) to get data size
fileLen = OutFile.Size
DataSize = fileLen-44
''write data size into appropriate locations in header
OutFile.WriteInt(36+DataSize,4)
OutFile.WriteInt(DataSize,40)
''close file again
OutFile.Close
RecOnLbl.Visible = False
ToastMessageShow("Recording Stopped", False)
End Sub

It's pretty weird, but it's the only way I have found so far to get this to work on the Galaxy S3 (Android version 4.1).

On my HTC Incredible, endedOK is passed as true and the Error string is pass as an empty string.

On the Galaxy, endedOK is false and the Error string is passed as "Exception: null"

Why closing and reopening the random access file and then finishing the header works, I don't know. Note that I am not flushing before closing. I suspect that I can do that before releasing AR, but have not been able to test this yet. It's really hard testing on machine hundreds of miles away :-(

Dave
 
Upvote 0

moster67

Expert
Licensed User
Longtime User
I tried your example you posted on my Galaxy S3 and I also get an error when clicking on Start Play-button:

main_playbtn_click (java line: 425)
java.io.IOException: setDataSourceFD failed.: status=0x80000000
at android.media.MediaPlayer.setDataSource(Native Method)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1225)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1197)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1143)
at anywheresoftware.b4a.objects.MediaPlayerWrapper.Load(MediaPlayerWrapper.java:84)
at b4a.example.main._playbtn_click(main.java:425)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:165)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:153)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:149)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:55)
at android.view.View.performClick(View.java:4211)
at android.view.View$PerformClick.run(View.java:17267)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
at dalvik.system.NativeStart.main(Native Method)
java.io.IOException: setDataSourceFD failed.: status=0x80000000

It seems like you are saving the audio-file in wav. Now I don't know much about audio-recording and this library but what about saving the audio in another format such as OGG (if possible)?

If I can help further with testing, let me know.
 
Last edited:
Upvote 0

Dave Fitzpatrick

Member
Licensed User
Longtime User
Thanks for your reply. Yes, I am saving the audio file in wav format. This is very important since it needs to be compatible with an app that runs on the PC and Mac that builds, saves, and plays wav files.

At this point, however, I don't think the problem has to do with the wav format, but revolves around the thread ending.

I will modify the file I uploaded to the "work around" that seems to play on my other testers' phones and see if you can determine anything about why the Rec_Ended(endedOK...) boolean variable is false on the Galaxy S3, since it is passed at true on my HTC Incredible (Android version 2.3.5)
 
Upvote 0

dclarkchem

Member
Licensed User
Longtime User
tried both the original recipe and the crispy version and got this error:

startRecording() called on an uninitialized AudioRecord.

Any help would be appreciated.
 
Upvote 0

mlc

Active Member
Licensed User
Longtime User
Not all devices support all sound configurations.

Try this code to see what values ​​are valid for your device
Libraries needed : Audiorecord

B4X:
Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim AudioSource As Int
   
   Dim BufferSize As Int
   Dim SampleRate() As Int 
   Dim AudioFormat() As Int
   Dim ChannelConfig() As Int
   Dim AudioFormats() As String
   Dim ChannelConfigs() As String   
   Dim AR As AudioRecord

End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   'Activity.LoadLayout("Layout1")

   
   AudioSource = AR.A_Src_Mic
   
   SampleRate =  Array As Int(8000, 11025, 22050, 44100)
   ChannelConfig = Array As Int(AR.CH_CONF_MONO, AR.CH_CONF_STEREO)
   ChannelConfigs = Array As String("CH_CONF_MONO", "CH_CONF_STEREO")
   AudioFormat = Array As Int(AR.AF_PCM_8, AR.AF_PCM_16)
   AudioFormats = Array As String("AF_PCM_8", "AF_PCM_16")
   
   Dim i, ii, iii As Int
   For i = 0 To SampleRate.Length - 1
      For ii = 0 To ChannelConfig.Length - 1
         For iii = 0 To AudioFormat.Length - 1
            BufferSize = AR.GetMinBufferSize(SampleRate(i), ChannelConfig(ii), AudioFormat(iii))
            If BufferSize <> AR.ERROR_BAD_VALUE Then
               AR.Initialize(AudioSource, SampleRate(i), ChannelConfig(ii), AudioFormat(iii), BufferSize)
                  If AR.GetState = AR.STATE_INITIALIZED Then
                     Log(SampleRate(i) & ", " & ChannelConfigs(ii) & ", " & AudioFormats(iii))
''                     AR.StartRecording
                  End If
            End If
         Next
      Next
   Next 
''   If AR.GetState = AR.STATE_INITIALIZED Then
''      AR.Stop
''      AR.release
''   End If
End Sub

Regards

Miguel
 
Upvote 0
Top