Как открыть файл filename.wav с менеджером активов только в c? Я работаю над этим в Android Studio 3.1.3

  1. Я создаю приложение для Android говорящих часов в Android Studio 3.1.3.
  2. Я добавляю native-audio, который был взят из GitHub. Это метод jni.

  3. В моем случае я хочу, чтобы он полностью работал в c.

  4. И я делаю это в ндк
  5. Все функции, упомянутые ниже, находятся в программе c.
  6. Logcat отображает "проверка актива Manager выполнена". Следующий журнал не отображается в logcat

int createAssetAudioPlayer (AAssetManager * assetManager, const char * filename) {

LOGI("creating... AssetAudioPlayer");
SLresult result;
// convert Java string to UTF-8
//const char *utf8 = (*env)->GetStringUTFChars(env, filename, NULL);
char fname[20];
strcpy(fname, filename);
const char *utf8 = malloc(sizeof(char) + strlen(fname));
strcpy(utf8, fname);
assert(NULL != utf8);
//assert(NULL != filename);
LOGI("File checking done");

// use asset manager to open asset by filename
//AAssetManager* mgr = AAssetManager_fromJava(env, assetManager);
AAssetManager *mgr = (void *)&assetManager;
assert(NULL != mgr);

LOGI("assetManager checking done");//Upto this line it is displayed in logcat
AAsset* asset = AAssetManager_open(mgr, utf8, AASSET_MODE_UNKNOWN);


LOGI("AAsset initialized");//Problem starts starts from here. This line does not display in logcat
// release the Java string and UTF-8
//(*env)->ReleaseStringUTFChars(env, filename, utf8);

// the asset might not be found
//if (NULL == asset) {
if(!asset){
    LOGI("AAsset not found");
    return 0;
}

// open asset as file descriptor
off_t start, length;
int fd = AAsset_openFileDescriptor(asset, &start, &length);
free(utf8);
assert(0 <= fd);
AAsset_close(asset);

// configure audio source
SLDataLocator_AndroidFD loc_fd = {SL_DATALOCATOR_ANDROIDFD, fd, start, length};
SLDataFormat_MIME format_mime = {SL_DATAFORMAT_MIME, NULL, SL_CONTAINERTYPE_UNSPECIFIED};
SLDataSource audioSrc = {&loc_fd, &format_mime};

// configure audio sink
SLDataLocator_OutputMix loc_outmix = {SL_DATALOCATOR_OUTPUTMIX, outputMixObject};
SLDataSink audioSnk = {&loc_outmix, NULL};

// create audio player
const SLInterfaceID ids[3] = {SL_IID_SEEK, SL_IID_MUTESOLO, SL_IID_VOLUME};
const SLboolean req[3] = {SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE};
result = (*engineEngine)->CreateAudioPlayer(engineEngine, &fdPlayerObject, &audioSrc, &audioSnk,
                                            3, ids, req);
assert(SL_RESULT_SUCCESS == result);
(void)result;

// realize the player
result = (*fdPlayerObject)->Realize(fdPlayerObject, SL_BOOLEAN_FALSE);
assert(SL_RESULT_SUCCESS == result);
(void)result;

// get the play interface
result = (*fdPlayerObject)->GetInterface(fdPlayerObject, SL_IID_PLAY, &fdPlayerPlay);
assert(SL_RESULT_SUCCESS == result);
(void)result;

// get the seek interface
result = (*fdPlayerObject)->GetInterface(fdPlayerObject, SL_IID_SEEK, &fdPlayerSeek);
assert(SL_RESULT_SUCCESS == result);
(void)result;

// get the mute/solo interface
result = (*fdPlayerObject)->GetInterface(fdPlayerObject, SL_IID_MUTESOLO, &fdPlayerMuteSolo);
assert(SL_RESULT_SUCCESS == result);
(void)result;

// get the volume interface
result = (*fdPlayerObject)->GetInterface(fdPlayerObject, SL_IID_VOLUME, &fdPlayerVolume);
assert(SL_RESULT_SUCCESS == result);
(void)result;

// enable whole file looping
result = (*fdPlayerSeek)->SetLoop(fdPlayerSeek, SL_BOOLEAN_TRUE, 0, SL_TIME_UNKNOWN);
assert(SL_RESULT_SUCCESS == result);
(void)result;

LOGI("Finished... creating assetAudioPlayer");

return 1;

}

logcat результат:

08-25 07:06:29.900 3125-3125/com.digitems.abongcher.kokjora I/KOKJORA: Inside Java main
08-25 07:14:19.576 3125-3125/com.digitems.abongcher.kokjora I/KOKJORA: Inside Java main
08-25 07:14:21.104 3125-3125/com.digitems.abongcher.kokjora I/KOKJORA: Inside Radio button
    15 min alarm triggered
08-25 07:14:21.104 3125-3125/com.digitems.abongcher.kokjora I/KOKJORA: Inside Native Method Key
    Inside Native Method alarm15Command
    Inside method sendCommand
    Inside native method saveKey
    3 saved in _kokjoraCommandKey.dat
    intent send to MiddleMan.class
08-25 07:14:21.116 3125-3125/com.digitems.abongcher.kokjora I/KOKJORA: We received the commandKey :3
08-25 07:14:21.120 3125-3125/com.digitems.abongcher.kokjora I/KOKJORA: Inside Native Method Key
    commandKey packed for delivery to backService.class
    intent send to bacService.class
08-25 07:14:21.120 3125-3157/com.digitems.abongcher.kokjora I/KOKJORA: We are inside backService.class
    Inside Native Method Key
    We received the commandKey :3
    Inside native method triggerAlarm
    Initializing... createEngine
08-25 07:14:21.120 3125-3157/com.digitems.abongcher.kokjora I/KOKJORA: Initialization of createEngine complete.
    Creating BufferQueueAudioPlayer
    Finished creating BufferQueueAudioPlayer
08-25 07:14:21.120 3125-3157/com.digitems.abongcher.kokjora E/KOKJORA: Failed to kill task
08-25 07:14:21.120 3125-3157/com.digitems.abongcher.kokjora I/KOKJORA: Continuing...
    continue2...
    continue3...
    continue4...
08-25 07:14:21.124 3125-3157/com.digitems.abongcher.kokjora I/KOKJORA: continue5...
    Process id 49 writen Successfully
    wait... sleeping for 1 minute and 21 seconds
08-25 07:15:00.128 3125-3157/com.digitems.abongcher.kokjora I/KOKJORA: Alarm ringing...Its 7 hour and 15 minute
08-25 07:15:00.128 3125-3157/com.digitems.abongcher.kokjora I/KOKJORA: creating... AssetAudioPlayer
    File checking done
    assetManager checking done

0 ответов

Другие вопросы по тегам