2

I've problem with loading mp3 file. when I give char array or jstring parameter to android java native method, c source file doesn't work.

maybe path parameter is not working correctly. what's wrong with it?

please answer to my question.

main.c


void Java_com_chocolate_player_PlayerMain_cPlaySound(JNIEnv env, jobject thiz, const char path) { FMOD_RESULT result = FMOD_OK;

result = FMOD_System_CreateSound(gSystem, path, FMOD_CREATECOMPRESSEDSAMPLE | FMOD_OPENMEMORY, 0, &gSound);
CHECK_RESULT(result);

__android_log_write(ANDROID_LOG_INFO, "path", path);

result = FMOD_System_PlaySound(gSystem, FMOD_CHANNEL_FREE, gSound, 0, &gChannel);
CHECK_RESULT(result);

}

android java source


in play method ... char[] fmodPath = songPath.replace("/mnt", "").toCharArray(); cPlaySound(fmodPath);

native method ... public native void cPlaySound(char[] path);

choijuho
  • 75
  • 1
  • 1
  • 8

1 Answers1

0

Add READ_EXTERNAL_STORAGE permission to your projects manifest:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> 

and path must begin with "/" symbol:

/sdcard/myfile.mp3
Tutankhamen
  • 3,532
  • 1
  • 30
  • 38
  • I added permission. android.permission.WRITE_EXTERNAL_STORAGE but result is same; and "/" added. log is like next 08-19 23:41:37.449: I/path(19222): (�@ – choijuho Aug 19 '12 at 14:42
  • I'm sure there is problem in file name... Try to add your own native method which opens given file name using fopen() and check i/o error... – Tutankhamen Aug 19 '12 at 14:53
  • I've used "/sdcard/music/kara.mp3" in Android and also in C source(main.c) when I tried in C source, it worked but in Android it didn't work. – choijuho Aug 19 '12 at 15:04
  • Can I meet you, Tutankhamen in mIRC? I might be crazy for this problem. huk huk... – choijuho Aug 19 '12 at 15:06
  • Sorry, i'm not actually online now... As I said, try to make your own native function in android and check why you can't open the file using fopen() function and then check the result... – Tutankhamen Aug 19 '12 at 15:12
  • without making fopen in C? Do I have to make android method for fopen? – choijuho Aug 19 '12 at 15:19
  • I made this function in C. and I've invoked this function in android. // C // void Java_com_chocolate_player_PlayerMain_cfopen(JNIEnv *env, jobject thiz, const char* path) { __android_log_write(ANDROID_LOG_INFO, "path", path); } // android // char[] fmodPath = testPath.toCharArray(); cfopen(fmodPath); – choijuho Aug 19 '12 at 15:24
  • Yes, in your native function at first line "void Java_com_chocolate_player_PlayerMain_cPlaySound(JNIEnv env, jobject thiz, const char path)" just try to call fopen(path,"rb") and check the result. – Tutankhamen Aug 19 '12 at 15:26
  • Thanks for reply in detail. I've followed your instruction. but it seems same result. after fopen(path, "rb") what do I have to do? – choijuho Aug 19 '12 at 15:39
  • how to print or see result of fopen()? – choijuho Aug 19 '12 at 15:47