android - MediaPlayer is not playing sound -
i creating media player. when press button (play) shows error.
08-20 11:35:21.473: d/mediaplayer(775): couldn't open file on client side, trying server side 08-20 11:35:21.493: e/mediaplayer(775): error (1, -2147483648) 08-20 11:35:21.503: w/system.err(775): java.io.ioexception: prepare failed.: status=0x1
my code
btnplay.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { uri audio = uri.parse("android.resourse://vishesh.mediaplayer/res/drawable/jannat"); try { mp.setdatasource(play.this,audio); mp.prepare(); mp.start(); } catch (illegalargumentexception e) { e.printstacktrace(); } catch (securityexception e) { e.printstacktrace(); } catch (illegalstateexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } btnplay.settext("pause"); } });
better place or put such .mp3 or other files in assets folder.
these files once stored become part of android app , can read easily.
play sound asset.
assetfiledescriptor afd = getassets().openfd("audiofile.mp3"); player = new mediaplayer(); player.setdatasource(afd.getfiledescriptor(),afd.getstartoffset(),afd.getlength()); player.prepare(); player.start();
Comments
Post a Comment