Android Question Problems playing audio from PCM file

Lakhtin_V

Active Member
Licensed User
Longtime User
I generate a list of PCM files and then click on the desired line. I read the file name through TAG. I can't understand why there is a problem playing sound from a PCM file. Sometimes the file plays successfully, sometimes not. Perhaps the reason is in the environment and the status of objects related to stream processing and player operation

PCM files:
    If File.Exists(File.DirInternal,fName)=True Then
        inFile = File.OpenInput(File.DirInternal, fName)
        If lstBuffer.IsInitialized Then
            lstBuffer.clear
            Else
            lstBuffer.Initialize
        End If

        Do While inFile.BytesAvailable > 0
            Dim buffer(bufferSize) As Byte
            Dim bytesRead As Int
            bytesRead = inFile.ReadBytes(buffer, 0, bufferSize)
            If bytesRead < bufferSize Then
                Dim actualBuffer(bytesRead) As Byte
                bc.ArrayCopy(buffer, 0, actualBuffer, 0, bytesRead)
                lstBuffer.Add(actualBuffer)
            Else
                lstBuffer.Add(buffer)
            End If
            If bytesRead = 0 Then Exit
        Loop
        inFile.Close
      x=lstBuffer.Size
        Log("        PlayStreamer lstBuffer.Size   " & x & "   yesPlay " & yesPlay & "   yesSoundRec " & yesSoundRec )
        If x>0 And yesPlay=False And yesSoundRec=False Then
            yesPlay=True
            Try
                streamer.StartPlaying
[B]                For Each b() As Byte In lstBuffer   ' 189 line[/B]
                    streamer.Write(b)
                Next
                streamer.Write(Null) 'when this "message" will be processed, the player will stop.
'                streamer.StopPlaying
                CallSub(General,"btnStop_Click")
                Catch
'                streamer.StopPlaying

Errors....

Error occurred on line: 189 (Starter)
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.media.AudioTrack.play()' on a null object reference
at anywheresoftware.b4a.audio.AudioStreamer.StartPlaying(AudioStreamer.java:120)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:205)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:6300)
at android.view.View$PerformClick.run(View.java:24955)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6550)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:857)
Сбой воспроизведения
Clicked on File: ~0~Не опознанный источник~865C~.pcm
Файл существует ~0~Не опознанный источник~865C~.pcm
ИГРАЮ PlayStreamer lstBuffer.Size 75 yesPlay true yesSoundRec false
Пустой буфер при проигрывании
Clicked on File: ~0~Не опознанный источник~9707~.pcm
Файл существует ~0~Не опознанный источник~9707~.pcm
ИГРАЮ PlayStreamer lstBuffer.Size 49 yesPlay true yesSoundRec false
Пустой буфер при проигрывании
 

Lakhtin_V

Active Member
Licensed User
Longtime User
I tried to insert
streamer.Initialize("streamer", mSampleRate, mMono, mBitRate, streamer.VOLUME_VOICE_CALL)
before the line
streamer.StartPlaying
it didn’t help, now I can’t hear anything at all. But when I create a stream from the microphone, it is successfully listened to and saved in the PCM file
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…