FMOD createSound error Android

Hi, I have installed fmod audio engine on android and its libraries in the correct form problem is in this code when i try to play and audio file

    std::string error = "";
    std::string path = "838726.mp3";
    auto aPath = FileUtils::getInstance()->fullPathForFilename(path);
    
    FMOD_RESULT result;

    FMOD::System *system = nullptr;
    // Create the main system object.
    result = FMOD::System_Create(&system);

    if (result != FMOD_OK && error.size() == 0)
        error = std::string(FMOD_ErrorString(result)) + ":" + std::to_string(__LINE__);

    result = system->init(16, FMOD_INIT_NORMAL, nullptr);

    if (result != FMOD_OK && error.size() == 0)
        error = std::string(FMOD_ErrorString(result)) + ":" + std::to_string(__LINE__);

    // Create the channel group.
    FMOD::ChannelGroup *channelGroup = nullptr;
    result = system->createChannelGroup("inGameSoundEffects", &channelGroup);

    if (result != FMOD_OK && error.size() == 0)
        error = std::string(FMOD_ErrorString(result)) + ":" + std::to_string(__LINE__);

    // Create the sound.
    FMOD::Sound *sound = nullptr;
    result = system->createSound(aPath, FMOD_DEFAULT, nullptr, &sound);

    if (result != FMOD_OK && error.size() == 0)
        error = std::string(FMOD_ErrorString(result)) + ":" + std::to_string(__LINE__);

    // Play the sound.
    FMOD::Channel *channel = nullptr;
    result = system->playSound(sound, nullptr, false, &channel);

    if (result != FMOD_OK && error.size() == 0)
        error = std::string(FMOD_ErrorString(result)) + ":" + std::to_string(__LINE__);

    // Assign the channel to the group.
    result = channel->setChannelGroup(channelGroup);

    if (result != FMOD_OK && error.size() == 0)
        error = std::string(FMOD_ErrorString(result)) + ":" + std::to_string(__LINE__);

the function createSound returns File not found error (FMOD_ERR_FILE_NOTFOUND) as a result while 838726.mp3 is in fact in the resources folder, fmod just cant seem to find it and i dont know the solution to this problem, even though i used fullPathForFilename, i looked everywhere mind you but found nothing

Thank you~

Have you checked that the result of fullPathForFilename() is returning the full platform-specific path to the mp3 file? If not, then that may be the cause of your problem.

Remember that all of your resources exist inside the APK file, so FMOD may not support reading a file that is inside the APK. You will need to ask the FMOD creators if it’s possible. If FMOD doesn’t support reading the file like that, then you’ll need to stream the data to FMOD, where you would take care of the file handling I/O.

1 Like

i figured it out thanks to you, in here Loading assets from Android APK Expansion? - FMOD Studio - FMOD Forums

indeed fullPathForFilename() returns “assets/838726.mp3” but for fmod to find that file in the assets the path needs to be reformatted like this “file:///android_asset/838726.mp3” it will then use the AAssetManager_open to find that file inside the apk and play my file :smiley:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.