Search code examples
androidsdksuperpowered

Can not open file from storage with superpowered sdk


I am using superpowered sdk for playing audio files. For this I use

player->open("/storage/emulated/0/0567894638.mp3");

I also add permission READ_EXTERNAL_STORAGE.

The issue is, there is no errors displaying but can not play file. If I take this same file from assets then it is successfully playing. Please someone tell me what changes i do for play from internal storage?


Solution

  • String file_path = "/storage/emulated/0/kal.mp3";
    File f = new File("" + file_path);
    fileLength = (int) f.length();
    
    Pair<Integer, Integer> deviceAudioInfo = getDeviceAudioInfo();
    Integer sampleRate = deviceAudioInfo.first;
    Integer bufferSize = deviceAudioInfo.second;
    SuperpoweredExample(sampleRate, bufferSize, file_path, 0, fileLength);
    
    
    SuperpoweredExample::SuperpoweredExample(unsigned int samplerate, unsigned int buffersize,
                                         const char *path, int fileOffset, int fileLength) : volume(1.0f * headroom) {
    stereoBuffer = (float *) memalign(16, (buffersize + 16) * sizeof(float) * 2);
    
    player = new SuperpoweredAdvancedAudioPlayer(&player, NULL, samplerate, 0);
    player->open(path);
    
    audioSystem = new SuperpoweredAndroidAudioIO(samplerate, buffersize, false, true,
                                                 audioProcessing,
                                                 this, -1, SL_ANDROID_STREAM_MEDIA, buffersize * 2);
    }
    

    add permission READ_EXTERNAL_STORAGE