i'm trying create little media player. therefor wrote code play .aac file located in assets folder:
public class fragmentdominik extends fragment { button button; view view; //mainactivity ma = new mainactivity(); public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view = inflater.inflate(r.layout.dominik,container, false); button = (button) view.findviewbyid(r.id.dominikbutton1); log.v("syx","in activity"); button.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { log.v("syx","clicked"); try { mediaplayer player = new mediaplayer(); assetfiledescriptor descriptor = view.getcontext().getassets().openfd("dome__heeey.aac"); /* if (ma.mp.isplaying()) { ma.mp.reset(); }*/ log.v("syx","playing"); player.setdatasource(descriptor.getfiledescriptor()); log.v("syx", "playing 2"); player.prepare(); log.v("syx", "playing 3"); player.start(); log.v("syx", "playing 4"); } catch (ioexception e) { } } }); return view; } }
but reason gives me error, when try play music, error appears after log "playing 2", error has player.prepare();. have no clue on causing error, appreciated :) edit: stacktrace
01-24 16:21:18.044 730-730/com.example.admin.soundboard v/syx: clicked 01-24 16:21:18.045 730-730/com.example.admin.soundboard v/syx: playing 01-24 16:21:18.052 730-730/com.example.admin.soundboard v/syx: playing 2 01-24 16:21:18.060 730-741/com.example.admin.soundboard e/mediaplayer: error (1, -2147483648) 01-24 16:21:18.061 730-730/com.example.admin.soundboard w/system.err: java.io.ioexception: prepare failed.: status=0x1 01-24 16:21:18.061 730-730/com.example.admin.soundboard w/system.err: @ android.media.mediaplayer._prepare(native method) 01-24 16:21:18.061 730-730/com.example.admin.soundboard w/system.err: @ android.media.mediaplayer.prepare(mediaplayer.java:1163) 01-24 16:21:18.061 730-730/com.example.admin.soundboard w/system.err: @ com.example.admin.soundboard.fragmentdominik$1.onclick(fragmentdominik.java:44) 01-24 16:21:18.061 730-730/com.example.admin.soundboard w/system.err: @ android.view.view.performclick(view.java:5198) 01-24 16:21:18.061 730-730/com.example.admin.soundboard w/system.err: @ android.view.view$performclick.run(view.java:21147) 01-24 16:21:18.061 730-730/com.example.admin.soundboard w/system.err: @ android.os.handler.handlecallback(handler.java:739) 01-24 16:21:18.061 730-730/com.example.admin.soundboard w/system.err: @ android.os.handler.dispatchmessage(handler.java:95) 01-24 16:21:18.061 730-730/com.example.admin.soundboard w/system.err: @ android.os.looper.loop(looper.java:148) 01-24 16:21:18.061 730-730/com.example.admin.soundboard w/system.err: @ android.app.activitythread.main(activitythread.java:5417) 01-24 16:21:18.061 730-730/com.example.admin.soundboard w/system.err: @ java.lang.reflect.method.invoke(native method) 01-24 16:21:18.061 730-730/com.example.admin.soundboard w/system.err: @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:726) 01-24 16:21:18.061 730-730/com.example.admin.soundboard w/system.err: @ com.android.internal.os.zygoteinit.main(zygoteinit.java:616)
Comments
Post a Comment