Coder Social home page Coder Social logo

Comments (5)

rh101 avatar rh101 commented on August 13, 2024

Please show the exact code used to preload the audio files

from axmol.

asnagni avatar asnagni commented on August 13, 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

from axmol.

rh101 avatar rh101 commented on August 13, 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.

from axmol.

rh101 avatar rh101 commented on August 13, 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

from axmol.

asnagni avatar asnagni commented on August 13, 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

from axmol.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.