video - IOException when playing .mp4 with android mediaplayer -


i trying play .mp4 file in mediaplayer throws ioexception @ mediaplayer.prepare():

09-21 12:59:33.570 14926-14937/com.alex.videoplayertest e/mediaplayer﹕ error (-2147483648, 0) 09-21 12:59:33.570 14926-14926/com.alex.videoplayertest w/system.err﹕ java.io.ioexception: prepare failed.: status=0x80000000 09-21 12:59:33.570 14926-14926/com.alex.videoplayertest w/system.err﹕ @ android.media.mediaplayer.prepare(native method) 09-21 12:59:33.570 14926-14926/com.alex.videoplayertest w/system.err﹕ @ com.alex.videoplayertest.mainactivity.onresume(mainactivity.java:53) 09-21 12:59:33.570 14926-14926/com.alex.videoplayertest w/system.err﹕ @ android.app.instrumentation.callactivityonresume(instrumentation.java:1185) 09-21 12:59:33.570 14926-14926/com.alex.videoplayertest w/system.err﹕ @ android.app.activity.performresume(activity.java:5182) 09-21 12:59:33.570 14926-14926/com.alex.videoplayertest w/system.err﹕ @ android.app.activitythread.performresumeactivity(activitythread.java:2732) 09-21 12:59:33.570 14926-14926/com.alex.videoplayertest w/system.err﹕ @ android.app.activitythread.handleresumeactivity(activitythread.java:2771) 09-21 12:59:33.570 14926-14926/com.alex.videoplayertest w/system.err﹕ @ android.app.activitythread.handlelaunchactivity(activitythread.java:2235) 09-21 12:59:33.570 14926-14926/com.alex.videoplayertest w/system.err﹕ @ android.app.activitythread.access$600(activitythread.java:141) 09-21 12:59:33.570 14926-14926/com.alex.videoplayertest w/system.err﹕ @ android.app.activitythread$h.handlemessage(activitythread.java:1234) 09-21 12:59:33.570 14926-14926/com.alex.videoplayertest w/system.err﹕ @ android.os.handler.dispatchmessage(handler.java:99) 09-21 12:59:33.570 14926-14926/com.alex.videoplayertest w/system.err﹕ @ android.os.looper.loop(looper.java:137) 09-21 12:59:33.570 14926-14926/com.alex.videoplayertest w/system.err﹕ @ android.app.activitythread.main(activitythread.java:5041) 09-21 12:59:33.570 14926-14926/com.alex.videoplayertest w/system.err﹕ @ java.lang.reflect.method.invokenative(native method) 09-21 12:59:33.570 14926-14926/com.alex.videoplayertest w/system.err﹕ @ java.lang.reflect.method.invoke(method.java:511) 09-21 12:59:33.570 14926-14926/com.alex.videoplayertest w/system.err﹕ @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) 09-21 12:59:33.570 14926-14926/com.alex.videoplayertest w/system.err﹕ @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) 09-21 12:59:33.570 14926-14926/com.alex.videoplayertest w/system.err﹕ @ dalvik.system.nativestart.main(native method)

here code:

public class mainactivity extends activity { private mediaplayer mediaplayer;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);  }  @override protected void onresume() {     super.onresume();     string file = "/storage/emulated/0/download/media/light_bulb.mp4";      file f = new file(file);     if (f.exists())     {         mediaplayer = new mediaplayer();         mediaplayer.setscreenonwhileplaying(true);         mediaplayer.setaudiostreamtype(audiomanager.stream_music);         mediaplayer.setonpreparedlistener(new mediaplayer.onpreparedlistener()         {             @override             public void onprepared(mediaplayer mp)             {                 if (mediaplayer != null)                     mediaplayer.start();             }         });          mediaplayer.reset();         try         {             fileinputstream fileinputstream = new fileinputstream(file);             mediaplayer.setdatasource(getapplicationcontext(), uri.parse(file));             fileinputstream.close();             mediaplayer.prepare();         }         catch (ioexception e)         {             e.printstacktrace();         }     } } 

}

can me out here?

try using

string file= environment.getexternalstoragedirectory().tostring()+"/download/media/_29187_v.1_light_bulb_16hd_25fps.mp4";  file f = new file(file); 

and add

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

to manifest file


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -