java - Can't play the recorded file -


i'm making app records audio long imagebutton touched , held. achieved following code:

public class mainactivity extends activity {  mediarecorder recorder; mediaplayer mediaplayer;  //storage paths string storagepath; string externalstoragepath;  //full output paths string externaloutputpath;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      //audio recorder     recorder = new mediarecorder();     recorder.reset();            recorder.setaudiosource(mediarecorder.audiosource.mic);     recorder.setoutputformat(mediarecorder.outputformat.three_gpp);     recorder.setaudioencoder(mediarecorder.audioencoder.amr_nb);     if (environment.getexternalstoragestate().equals(environment.media_mounted))     {         externalstoragepath = environment.getexternalstoragedirectory().getabsolutepath();         externaloutputpath = externalstoragepath + file.separator + "/android/data/com.whizzappseasyvoicenotepad/test.mp3";         recorder.setoutputfile(externaloutputpath);     }     else     {         storagepath = environment.getdatadirectory().getabsolutepath();         recorder.setoutputfile(storagepath + "/android/data/com.whizzappseasyvoicenotepad/test.mp3");     }      //image button ontouchlistener     final imagebutton recbtn = (imagebutton) findviewbyid(r.id.recbutton);     recbtn.setontouchlistener(new ontouchlistener(){          @override         public boolean ontouch(view v, motionevent event) {              if (event.getaction() == motionevent.action_down)             {                 recbtn.setimageresource(r.drawable.record_btn_pressed);                 try {                     recorder.prepare();                     recorder.start();                 } catch (illegalstateexception e) {                     // todo auto-generated catch block                     e.printstacktrace();                 } catch (ioexception e) {                     // todo auto-generated catch block                     e.printstacktrace();                 }             }             else if (event.getaction() == motionevent.action_up)             {                 recbtn.setimageresource(r.drawable.record_btn);                 try {                     recorder.prepare();                     recorder.stop();                     recorder.reset();                     recorder.release();                     recorder = null;                 } catch (illegalstateexception e) {                     // todo auto-generated catch block                     e.printstacktrace();                 } catch (ioexception e) {                     // todo auto-generated catch block                     e.printstacktrace();                 }                 log.i(storage_service, "file saved to: " + externalstoragepath + "/android/data/com.whizzappseasyvoicenotepad/test.3gp");             }             return true;         }      }); } //end of oncreate 

now after i've stopped recording, searched mp3 file in file manager (android app) , tried playing music player doesn't work. says file can't played.

i tried add "test play" button app, try , play recorded file mediaplayer doesn't work either. press play button, app crashes.

public void testplay (view v) throws illegalargumentexception, securityexception, illegalstateexception, ioexception{     mediaplayer = new mediaplayer();     mediaplayer.setdatasource(externaloutputpath);     mediaplayer.start(); } 

yes, did add android:onclick="testplay" xml file

logcat file:

07-31 16:51:43.938: e/mediaplayer(26918): unable to create media player 07-31 16:51:43.953: e/androidruntime(26918): fatal exception: main 07-31 16:51:43.953: e/androidruntime(26918): java.lang.illegalstateexception: not execute method of activity 07-31 16:51:43.953: e/androidruntime(26918):    @ android.view.view$1.onclick(view.java:3633) 07-31 16:51:43.953: e/androidruntime(26918):    @ android.view.view.performclick(view.java:4240) 07-31 16:51:43.953: e/androidruntime(26918):    @ android.view.view$performclick.run(view.java:17721) 07-31 16:51:43.953: e/androidruntime(26918):    @ android.os.handler.handlecallback(handler.java:730) 07-31 16:51:43.953: e/androidruntime(26918):    @ android.os.handler.dispatchmessage(handler.java:92) 07-31 16:51:43.953: e/androidruntime(26918):    @ android.os.looper.loop(looper.java:137) 07-31 16:51:43.953: e/androidruntime(26918):    @ android.app.activitythread.main(activitythread.java:5103) 07-31 16:51:43.953: e/androidruntime(26918):    @ java.lang.reflect.method.invokenative(native method) 07-31 16:51:43.953: e/androidruntime(26918):    @ java.lang.reflect.method.invoke(method.java:525) 07-31 16:51:43.953: e/androidruntime(26918):    @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:737) 07-31 16:51:43.953: e/androidruntime(26918):    @ com.android.internal.os.zygoteinit.main(zygoteinit.java:553) 07-31 16:51:43.953: e/androidruntime(26918):    @ dalvik.system.nativestart.main(native method) 07-31 16:51:43.953: e/androidruntime(26918): caused by: java.lang.reflect.invocationtargetexception 07-31 16:51:43.953: e/androidruntime(26918):    @ java.lang.reflect.method.invokenative(native method) 07-31 16:51:43.953: e/androidruntime(26918):    @ java.lang.reflect.method.invoke(method.java:525) 07-31 16:51:43.953: e/androidruntime(26918):    @ android.view.view$1.onclick(view.java:3628) 07-31 16:51:43.953: e/androidruntime(26918):    ... 11 more 07-31 16:51:43.953: e/androidruntime(26918): caused by: java.io.ioexception: setdatasourcefd failed.: status=0x80000000 07-31 16:51:43.953: e/androidruntime(26918):    @ android.media.mediaplayer.setdatasource(native method) 07-31 16:51:43.953: e/androidruntime(26918):    @ android.media.mediaplayer.setdatasource(mediaplayer.java:981) 07-31 16:51:43.953: e/androidruntime(26918):    @ android.media.mediaplayer.setdatasource(mediaplayer.java:960) 07-31 16:51:43.953: e/androidruntime(26918):    @ android.media.mediaplayer.setdatasource(mediaplayer.java:918) 07-31 16:51:43.953: e/androidruntime(26918):    @ com.whizzappseasyvoicenotepad.mainactivity.testplay(mainactivity.java:99) 07-31 16:51:43.953: e/androidruntime(26918):    ... 14 more 

permissions:

<uses-permission android:name="android.permission.record_audio" /> <uses-permission android:name="android.permission.write_external_storage"/> <uses-permission android:name="android.permission.storage" /> <uses-permission android:name="android.permission.internet" /> <uses-permission android:name="android.permission.access_network_state" /> 

java.lang.illegalstateexception 

often indicates permission missing in manifest.xml


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -