Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android: Axmol is failing to play wav and mp3 audio file format #1921

Closed
asnagni opened this issue May 22, 2024 · 5 comments
Closed

Android: Axmol is failing to play wav and mp3 audio file format #1921

asnagni opened this issue May 22, 2024 · 5 comments
Labels
Milestone

Comments

@asnagni
Copy link

asnagni commented May 22, 2024

Hello,
On Android platform when we try to preload .wav or .mp3 audio files, the operation will fail. These formats are supposed to be supported by Axmol as far as I understand it. Maybe we need to setup a flag in the project CMake file? We are not sure at this point.

When the app is running, the files are located in a folder named "voiceMesages" in the app writable path.
When we try to preload the files the App will crash.

  • axmol version: development branch
  • devices test on: Redmi Note 8 & 9, Google Pixel 8, Samsung Galaxy S24, Samsung Galaxy A73 (Android 11, 13 and 14)
  • developing environments
    • NDK version: 22.1.7171670
    • Xcode version: N/A
    • Visual Studio: N/A
      • VS version: N/A
      • MSVC version: N/A
      • Windows SDK version: N/A
    • cmake version: 3.29.0
      Steps to Reproduce:
  1. Create a simple Axmole project
  2. Add the files somewhere in your writable path
  3. preload the files
  4. Play the sound

audioFiles.zip

Thank you for your help,
Stay safe

@rh101
Copy link
Contributor

rh101 commented May 23, 2024

Please show the exact code used to preload the audio files

@asnagni
Copy link
Author

asnagni commented May 23, 2024

Hi rh101,
Sure, not a problem. The exact layout is that you have a tableview with a number of cells. When you click on a given table cell, the sound associated to that cell will play the audio file. To help, I would like to point out that it is working without any issue on iOS (iPhone & iPad). Please see the code below and let me know if there is something wrong with the way the API is used :

    bool CChatDialogLayer::playSound(ssize_t idx)
    {
        if (idx < 0 || idx >= m_messages.size()) return false;

        CConnexionMessage::MessageType msgType = m_messages[idx].getType();
        bool playSoundMsg = (msgType == CConnexionMessage::MessageTypeSound);
        if (!playSoundMsg) return false;

        std::string strMsg = m_messages[idx].getText();

        // Check if we have a direct access to the audio file.
        // If not, we need to download it and play it
        std::string file = m_messages[idx].getExistingFilePath();

        if (!file.empty())
        {
            playSoundMsg = true;
        }
        else
        {
            m_savedAudioFileName = strMsg;
            m_audioIdx = idx;

            requestFirebaseDownload((int)CConnexionMessage::MessageTypeSound,strMsg);
            playSoundMsg = false;
        }


        if (playSoundMsg)
        {
#if AX_TARGET_PLATFORM == AX_PLATFORM_IOS
            IOSManager::ConfigureAVAudioSession();
#endif
            AudioEngine::preload(file, [&, file](bool success) {
                if(success)
                {
                    int aid = AudioEngine::play2d(file, false, 1.0f, nullptr);
                    if (aid == AudioEngine::INVALID_AUDIO_ID) return false;

                    m_audioID = aid;
                    m_audioIdx = idx;
                    m_audioFile = file;

                    if(aid != AudioEngine::INVALID_AUDIO_ID)
                    {
                        AudioEngine::setFinishCallback(m_audioID, [&] (int audioID, std::string_view file) {
                            if (audioID == m_audioID)
                            {
                                ssize_t save_idx = m_audioIdx;
                                stopSound(false);
                                m_pTableView->updateCellAtIndex(save_idx);
                            }
                        });
                    }
                }
            });
        }

        return playSoundMsg;
    }

Thank you,
Stay safe

@rh101
Copy link
Contributor

rh101 commented May 23, 2024

@asnagni The MP3 file is not using the MP3 codec, but rather the MP4A codec, as you can see here:
image

The file extension is not entirely relevant, so when encoding to MP3, ensure that you're using an MP3 codec, such as this:
image

This is not a bug with Axmol. The reason the "Test.mp3" file is working on iOS is because the MP4A format is supported on iOS.

@rh101
Copy link
Contributor

rh101 commented May 23, 2024

The WAV file is in the following format:
image

I'm not sure if the SAMR format is supported, and it does not seem to be a valid format for WAV files. The correct extension for a file encoded in that format should be .amr or .3ga. Once again, the file extension is not important, but the internal encoding is, so it is not playing the file because it is not actually in a supported WAV format. The "test2.wav" file doesn't play on Windows builds either.

WAV data formats that are supported can be seen here in the cpp-tests project:
image

For example, PCM, u-Law etc.

In AudioCache.cpp, you can see the supported formats:
image

@asnagni
Copy link
Author

asnagni commented May 27, 2024

Hi rh101,
Sorry for the delay in my responce. Thank you very much for all the details that you provided. I spent lot of time trying the sounds located test area and they are working. Axmol is working fine without any issue per the document (supported format). Unfortunately for our use case the supported format are a bit limited. I spent some time testing Axmol to see if I could find a solution but finaly a will be using ExoPlayer2 (it supports much more format than MediaPlayer and it is very easy to implement).
That way we will not run the risk of having some crashes due to unsorted format.

 Thank you very much rh101 for your support 👍, I do appreciate.
 Stay safe

@asnagni asnagni closed this as completed May 27, 2024
@halx99 halx99 added this to the HelpDesk milestone May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants