iOS Question audio from Ipad doesn't work on android

stephane..blusson

Member
Licensed User
Hello. I have a problem.
I already created a topic that audio messages on iOS are not played, I solved this problem using the WAV audio files.

now the audio that was generated on ios or android works on my ipad.
But now audio created on ipad doesn't work on android.

I'm using this code to record audio files

B4X:
Private Sub btnVoiceMessageStart_Click 
        StartRecording
End Sub

Sub StartRecording
    Try
        audioMessageName = generateAudioMessageName
        recorder.Initialize(shared, audioMessageName & ".WAV", 44100, True, 16, False)
        recorder.Record
    Catch
        Log("StartRecording " & LastException.description)
    End Try
End Sub

Private Sub btnVoiceMessageStop_Click
 

    Try
        recorder.Stop
        Log("StopRecording OK")
    Catch
        Log("StopRecording " & LastException.description)
    End Try
     
  'and ftp logic
End Sub

when I download this file using ftp on android, it shows the file length 5000+ or other strange large numbers, and infinitely calls the method Sub MP_Complete

screenshot of this error

1636962237709.png




A very simple example to demonstrate the error
 

Attachments

  • ftp-logic-test.zip
    11.9 KB · Views: 57
  • ftp-logic-test-ios.zip
    4.7 KB · Views: 59
Last edited:

Semen Matusovskiy

Well-Known Member
Licensed User
It looks like a problem in 'ftp logic'. Libraries, which are needed, are enough old, so it's hard to imagine hidden errors.
Make a small project, which demonstate a problem (B4i & B4A)

BTW, why FTP ? Your password is visible in proxy.
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
I looked B4i part only. Does not notice TYPE BINARY ftp command (typically. default is TYPE ASCII). So, some symbols can be wrong.
But anyway, a length of uploaded file is correct, I was able to play it under Windows (using CuteFTP).
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
B4A ... After some experiments it looks that B4I (probably) creates files, which are incompatible with B4i (unsupported codecs).
For example, I ran Total Commander on Android. It can't play a file which was recorded under IOS.
But VLC under Android and Windows 11 plays a file without problems.
 
Last edited:
Upvote 0

stephane..blusson

Member
Licensed User
B4A ... After some experiments it looks that B4I (probably) creates files, which are incompatible with B4i (unsupported codecs).
For example, I ran Total Commander on Android. It can't play a file which was recorded under IOS.
But VLC under Android and Windows 11 plays a file without problems.
Thanks for the advice. I created a xml file network_security_config and put it in "...\B4A\Objects\res\xml", add in manifest file
B4X:
SetApplicationAttribute(android:networkSecurityConfig, @xml/network_security_config)

the file is rewritten all the time like this:


B4X:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
    <trust-anchors>
        <certificates src="system" />
    </trust-anchors>
</base-config>
</network-security-config>

The error has not changed.

But it seems to me that there is no problem with the connection, because the video created on the IOS is loaded and works on Android
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
Security is a problem for streams. It's not our case.

Just now I think about https://developer.apple.com/documentation/avfaudio/avaudiorecorder/1388386-initwithurl?language=objc (it's possible to select audio format).
I will try to play with settings tonight and will inform about results.

Added ...

I did experiments with recorder.Initialize and Initialize2.
If to use Initialize, B4i sets AVFormatIDKey = kAudioFormatLinearPCM (1819304813) and AVAudioFileTypeKey = kAudioFileCAFType (1667327590).
With this parameters IOS creates a caf file (Apple's format), not a wav file. This explains why such programs as Windows Media, Music Groove, IrfanView refuse to play under Windows.

If to use Initialize2 and to set AVAudioFileTypeKey = kAudioFileWAVEType, IOS sets RIFF in bytes 0-3 like in Microsoft WAV. But another fields conflict with standard anyway. For example, in bytes 8-11 should be WAVE, but there is desc. So, at least header conflicts with Microsoft WAV format.

VLC understands IOS formats, but this confirms that this is a very powerful program only.
 
Last edited:
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
First good news. IOS is able to create mp4 file, Android is able to play it.
What I changed in your B4i code.

1) Before download/upload I added ftp.SendCommand ("TYPE", "BINARY")
2) testaudio.wav renamed to testaudio.mp4
3) replaced recorder.Initialize (...) to
B4X:
    Dim Settings As Map
    Settings.Initialize
        Settings.Put ("AVFormatIDKey", kAudioFormatMPEG4AAC)
        Settings.Put ("AVEncoderAudioQualityKey", AVAudioQualityMax)
        Settings.Put ("AVNumberOfChannelsKey", 1)
        Settings.Put ("AVEncoderBitRateKey", 16000)
        Settings.Put ("AVSampleRateKey", 16000)
                 
        recorder.Initialize2(shared, audioMessageName, Settings)

4) Constants (not all are needed) in Class_Globals:
B4X:
    Public Const kAudioFormatLinearPCM              As Int = 1819304813                  
    Public Const kAudioFormatAC3                    As Int = 1633889587
    Public Const kAudioFormat60958AC3               As Int = 1667326771
    Public Const kAudioFormatAppleIMA4              As Int = 1768775988
    Public Const kAudioFormatMPEG4AAC               As Int = 1633772320
    Public Const kAudioFormatMPEG4CELP              As Int = 1667591280
    Public Const kAudioFormatMPEG4HVXC              As Int = 1752594531
    Public Const kAudioFormatMPEG4TwinVQ            As Int = 1953986161
    Public Const kAudioFormatMACE3                  As Int = 1296122675
    Public Const kAudioFormatMACE6                  As Int = 1296122678
    Public Const kAudioFormatULaw                   As Int = 1970037111
    Public Const kAudioFormatALaw                   As Int = 1634492791
    Public Const kAudioFormatQDesign                As Int = 1363430723
    Public Const kAudioFormatQDesign2               As Int = 1363430706
    Public Const kAudioFormatQUALCOMM               As Int = 1365470320
    Public Const kAudioFormatMPEGLayer1             As Int = 778924081
    Public Const kAudioFormatMPEGLayer2             As Int = 778924082
    Public Const kAudioFormatMPEGLayer3             As Int = 778924083
    Public Const kAudioFormatTimeCode               As Int = 1953066341
    Public Const kAudioFormatMIDIStream             As Int = 1835623529
    Public Const kAudioFormatParameterValueStream   As Int = 1634760307
    Public Const kAudioFormatAppleLossless          As Int = 1634492771
    Public Const kAudioFormatMPEG4AAC_HE            As Int = 1633772392
    Public Const kAudioFormatMPEG4AAC_LD            As Int = 1633772396
    Public Const kAudioFormatMPEG4AAC_ELD           As Int = 1633772389
    Public Const kAudioFormatMPEG4AAC_ELD_SBR       As Int = 1633772390
    Public Const kAudioFormatMPEG4AAC_ELD_V2        As Int = 1633772391
    Public Const kAudioFormatMPEG4AAC_HE_V2         As Int = 1633772400
    Public Const kAudioFormatMPEG4AAC_Spatial       As Int = 1633772403
    Public Const kAudioFormatMPEGD_USAC             As Int = 1970495843
    Public Const kAudioFormatAMR                    As Int = 1935764850
    Public Const kAudioFormatAMR_WB                 As Int = 1935767394
    Public Const kAudioFormatAudible                As Int = 1096107074
    Public Const kAudioFormatiLBC                   As Int = 1768710755
    Public Const kAudioFormatDVIIntelIMA            As Int = 1836253201
    Public Const kAudioFormatMicrosoftGSM           As Int = 1836253233
    Public Const kAudioFormatAES3                   As Int = 1634038579
    Public Const kAudioFormatEnhancedAC3            As Int = 1700998451
    Public Const kAudioFormatFLAC                   As Int = 1718378851
    Public Const kAudioFormatOpus                   As Int = 1869641075
   
    Public Const kAudioFileWAVEType                 As Int = 1463899717
    Public Const kAudioFileAIFFType                 As Int = 1095321158
    Public Const kAudioFileAIFCType                 As Int = 1095321155
    Public Const kAudioFileWAVEType                 As Int = 1463899717
    Public Const kAudioFileSoundDesigner2Type       As Int = 1399075430
    Public Const kAudioFileNextType                 As Int = 1315264596
    Public Const kAudioFileMP3Type                  As Int = 1297106739
    Public Const kAudioFileMP2Type                  As Int = 1297106738
    Public Const kAudioFileMP1Type                  As Int = 1297106737
    Public Const kAudioFileAC3Type                  As Int = 1633889587
    Public Const kAudioFileAAC_ADTSType             As Int = 1633973363
    Public Const kAudioFileMPEG4Type                As Int = 1836069990
    Public Const kAudioFileM4AType                  As Int = 1832149350
    Public Const kAudioFileCAFType                  As Int = 1667327590
    Public Const kAudioFile3GPType                  As Int = 862417008
    Public Const kAudioFile3GP2Type                 As Int = 862416946
    Public Const kAudioFileAMRType                  As Int = 1634562662

    Public Const AVAudioQualityMin                  As Int = 0
    Public Const AVAudioQualityLow                  As Int = 32
    Public Const AVAudioQualityMedium               As Int = 64
    Public Const AVAudioQualityHigh                 As Int = 96
    Public Const AVAudioQualityMax                  As Int = 127
 
Last edited:
Upvote 0

stephane..blusson

Member
Licensed User
First good news. IOS is able to create mp4 file, Android is able to play it.
What I changed in your B4i code.

1) Before download/upload I added ftp.SendCommand ("TYPE", "BINARY")
2) testaudio.wav renamed to testaudio.mp4
3) replaced recorder.Initialize (...) to
B4X:
    Dim Settings As Map
    Settings.Initialize
        Settings.Put ("AVFormatIDKey", kAudioFormatMPEG4AAC)
        Settings.Put ("AVEncoderAudioQualityKey", AVAudioQualityMax)
        Settings.Put ("AVNumberOfChannelsKey", 1)
        Settings.Put ("AVEncoderBitRateKey", 16000)
        Settings.Put ("AVSampleRateKey", 16000)
                
        recorder.Initialize2(shared, audioMessageName, Settings)

4) Constants (not all are needed) in Class_Globals:
B4X:
    Public Const kAudioFormatLinearPCM              As Int = 1819304813                 
    Public Const kAudioFormatAC3                    As Int = 1633889587
    Public Const kAudioFormat60958AC3               As Int = 1667326771
    Public Const kAudioFormatAppleIMA4              As Int = 1768775988
    Public Const kAudioFormatMPEG4AAC               As Int = 1633772320
    Public Const kAudioFormatMPEG4CELP              As Int = 1667591280
    Public Const kAudioFormatMPEG4HVXC              As Int = 1752594531
    Public Const kAudioFormatMPEG4TwinVQ            As Int = 1953986161
    Public Const kAudioFormatMACE3                  As Int = 1296122675
    Public Const kAudioFormatMACE6                  As Int = 1296122678
    Public Const kAudioFormatULaw                   As Int = 1970037111
    Public Const kAudioFormatALaw                   As Int = 1634492791
    Public Const kAudioFormatQDesign                As Int = 1363430723
    Public Const kAudioFormatQDesign2               As Int = 1363430706
    Public Const kAudioFormatQUALCOMM               As Int = 1365470320
    Public Const kAudioFormatMPEGLayer1             As Int = 778924081
    Public Const kAudioFormatMPEGLayer2             As Int = 778924082
    Public Const kAudioFormatMPEGLayer3             As Int = 778924083
    Public Const kAudioFormatTimeCode               As Int = 1953066341
    Public Const kAudioFormatMIDIStream             As Int = 1835623529
    Public Const kAudioFormatParameterValueStream   As Int = 1634760307
    Public Const kAudioFormatAppleLossless          As Int = 1634492771
    Public Const kAudioFormatMPEG4AAC_HE            As Int = 1633772392
    Public Const kAudioFormatMPEG4AAC_LD            As Int = 1633772396
    Public Const kAudioFormatMPEG4AAC_ELD           As Int = 1633772389
    Public Const kAudioFormatMPEG4AAC_ELD_SBR       As Int = 1633772390
    Public Const kAudioFormatMPEG4AAC_ELD_V2        As Int = 1633772391
    Public Const kAudioFormatMPEG4AAC_HE_V2         As Int = 1633772400
    Public Const kAudioFormatMPEG4AAC_Spatial       As Int = 1633772403
    Public Const kAudioFormatMPEGD_USAC             As Int = 1970495843
    Public Const kAudioFormatAMR                    As Int = 1935764850
    Public Const kAudioFormatAMR_WB                 As Int = 1935767394
    Public Const kAudioFormatAudible                As Int = 1096107074
    Public Const kAudioFormatiLBC                   As Int = 1768710755
    Public Const kAudioFormatDVIIntelIMA            As Int = 1836253201
    Public Const kAudioFormatMicrosoftGSM           As Int = 1836253233
    Public Const kAudioFormatAES3                   As Int = 1634038579
    Public Const kAudioFormatEnhancedAC3            As Int = 1700998451
    Public Const kAudioFormatFLAC                   As Int = 1718378851
    Public Const kAudioFormatOpus                   As Int = 1869641075
  
    Public Const kAudioFileWAVEType                 As Int = 1463899717
    Public Const kAudioFileAIFFType                 As Int = 1095321158
    Public Const kAudioFileAIFCType                 As Int = 1095321155
    Public Const kAudioFileWAVEType                 As Int = 1463899717
    Public Const kAudioFileSoundDesigner2Type       As Int = 1399075430
    Public Const kAudioFileNextType                 As Int = 1315264596
    Public Const kAudioFileMP3Type                  As Int = 1297106739
    Public Const kAudioFileMP2Type                  As Int = 1297106738
    Public Const kAudioFileMP1Type                  As Int = 1297106737
    Public Const kAudioFileAC3Type                  As Int = 1633889587
    Public Const kAudioFileAAC_ADTSType             As Int = 1633973363
    Public Const kAudioFileMPEG4Type                As Int = 1836069990
    Public Const kAudioFileM4AType                  As Int = 1832149350
    Public Const kAudioFileCAFType                  As Int = 1667327590
    Public Const kAudioFile3GPType                  As Int = 862417008
    Public Const kAudioFile3GP2Type                 As Int = 862416946
    Public Const kAudioFileAMRType                  As Int = 1634562662

    Public Const AVAudioQualityMin                  As Int = 0
    Public Const AVAudioQualityLow                  As Int = 32
    Public Const AVAudioQualityMedium               As Int = 64
    Public Const AVAudioQualityHigh                 As Int = 96
    Public Const AVAudioQualityMax                  As Int = 127
Hi, thanks for the answer. I will definitely test this solution too. But now I have found a solution, but still need to test.
I replaced initialization with

B4X:
recorder.Initialize(shared, audioMessageName, 44100, True, 8, True) 'MPEG4 = true

And I replaced the file format with m4a for both platforms.
 
Upvote 0
Top