Unsolved: Android audio recording using example from Google -


i'm learning how record audio using http://developer.android.com/guide/topics/media/audio-capture.html#example

everything works fine, want switch:

mfilename = environment.getexternalstoragedirectory().getabsolutepath(); mfilename += "/audiorecordtest.3gp"; 

to

mfilename = getfilesdir().getabsolutepath(); mfilename += "/audiorecordtest.3gp"; 

but error

08-19 15:51:44.212: e/mediaplayer(6654): error (1, -2147483648) 08-19 15:51:44.212: e/audiorecordtest(6654): prepare() failed 

i tried log new code (to make sure i'm using valid path).

note:

this works on samsung galaxy, doesn't work on nexus one. want work on 2.x, 3.x, , 4.x

update: added log in startrecording():

mrecorder.setoutputfile(mfilename);         log.e("log", mfilename); 

the output of log is:

08-22 12:28:40.112: e/log(9666): /data/data/com.example.testrecorder/files/audiorecordtest.3gp 

tried logging exception:

  private void startplaying() {         mplayer = new mediaplayer();         try {             mplayer.setdatasource(mfilename);             mplayer.prepare();             mplayer.start();         } catch (ioexception e) {             log.e(log_tag, "prepare() failed", e);         }     }  08-22 13:08:03.158: e/mediaplayer(10093): error (1, -2147483648) 08-22 13:08:03.168: e/audiorecordtest(10093): prepare() failed 08-22 13:08:03.168: e/audiorecordtest(10093): java.io.ioexception: prepare failed.: status=0x1 08-22 13:08:03.168: e/audiorecordtest(10093):   @ android.media.mediaplayer.prepare(native method) 08-22 13:08:03.168: e/audiorecordtest(10093):   @ com.example.testrecorder.mainactivity.startplaying(mainactivity.java:51) 08-22 13:08:03.168: e/audiorecordtest(10093):   @ com.example.testrecorder.mainactivity.onplay(mainactivity.java:41) 08-22 13:08:03.168: e/audiorecordtest(10093):   @ com.example.testrecorder.mainactivity.access$1(mainactivity.java:39) 08-22 13:08:03.168: e/audiorecordtest(10093):   @ com.example.testrecorder.mainactivity$playbutton$1.onclick(mainactivity.java:113) 08-22 13:08:03.168: e/audiorecordtest(10093):   @ android.view.view.performclick(view.java:2532) 08-22 13:08:03.168: e/audiorecordtest(10093):   @ android.view.view$performclick.run(view.java:9308) 08-22 13:08:03.168: e/audiorecordtest(10093):   @ android.os.handler.handlecallback(handler.java:587) 08-22 13:08:03.168: e/audiorecordtest(10093):   @ android.os.handler.dispatchmessage(handler.java:92) 08-22 13:08:03.168: e/audiorecordtest(10093):   @ android.os.looper.loop(looper.java:150) 08-22 13:08:03.168: e/audiorecordtest(10093):   @ android.app.activitythread.main(activitythread.java:4333) 08-22 13:08:03.168: e/audiorecordtest(10093):   @ java.lang.reflect.method.invokenative(native method) 08-22 13:08:03.168: e/audiorecordtest(10093):   @ java.lang.reflect.method.invoke(method.java:507) 08-22 13:08:03.168: e/audiorecordtest(10093):   @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:839) 08-22 13:08:03.168: e/audiorecordtest(10093):   @ com.android.internal.os.zygoteinit.main(zygoteinit.java:597) 08-22 13:08:03.168: e/audiorecordtest(10093):   @ dalvik.system.nativestart.main(native method) 

when create new mediaplayer object, it's not part of your app, it's part of system. because true, can't read files in app's private directory unless world_readable. that's why works external directory , not internal one. yes, sounds ridiculous, agree.

you should able around creating filedescriptor , passing mediaplayer way:

fileinputstream fis = new fileinputstream(mfilename); mplayer.setdatasource(fis.getfd()); 

note: gtkandroid gives a more thorough explanation, found through bug tracker. if works you, i'd suggest upvote answer on other question well.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -