Android Question error when trying to run Audiostream example

Olivier Zeegers

Active Member
Licensed User
Hello I get this error when trying to run the Audiostream example on my device:

Installing file to device. Error
adb: failed to install 1_RAPID_DEBUG.apk: Failure [-26: Package b4a.example new target SDK 14 doesn't support runtime permissions but the old target SDK 26 does.]

what does this mean ?

thank you
 

Olivier Zeegers

Active Member
Licensed User
OK, I changed targetSdkVersion from 14 to 26 in the Manifest Editor and it runs..

but, when I press the startrecording button it gives me this error:

Error occurred on line: 47 (Main)
java.lang.IllegalStateException: startRecording() called on an uninitialized AudioRecord.

when I put a log("initialized") just below the streamer.initialize function in Activity_Create it does show it was initialized ?

sorry, just started using B4A and thus a newbee...
Can someone point me out what is wrong ? The Audio libraries where already installed.

thank you
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Add this line in Globals:
Private RP As RuntimePermissions

This line in Activity_Create:
RP.CheckAndRequest(RP.PERMISSION_RECORD_AUDIO)

And this routine:
B4X:
Private Sub Activity_PermissionResult (Permission As String, Result As Boolean)
    If Permission = RP.PERMISSION_RECORD_AUDIO Then
        AudioStreamer1.Initialize("AudioStreamer1", Starter.SampleRate, ChannelMono, AudioFormat, AudioStreamer1.VOLUME_MUSIC)
    End If
End Sub
 
Upvote 0

Olivier Zeegers

Active Member
Licensed User


Thank you Klaus from Switzerland !

I have coded it like this and it works... I found that I had to enable the RunTimePermissions library in the Library Manager..

B4X:
    RP.CheckAndRequest(RP.PERMISSION_RECORD_AUDIO)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result = True Then
        Activity.LoadLayout("1")
        If FirstTime Then
            streamer.Initialize("streamer", 44100, True, 16, streamer.VOLUME_MUSIC)
            buffers.Initialize
            timer1.Initialize("timer1", 1000)
        End If
    End If
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…