audio - Play a sound in android -


how make android app plays sound on click of button ? suppose, sound file a.mp3 inside res\sound\ how should play ? in advance.

first of have create folder called raw put there music want play , :

 public class testsound extends activity {     @override     protected void oncreate(bundle savedinstancestate) {                 super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          button btsound = (button)this.findviewbyid(r.id.button1);         final mediaplayer mp = mediaplayer.create(this, r.raw.musictest);         btsound .setonclicklistener(new onclicklistener(){              public void onclick(view v) {                 mp.start();             }         });          } 

supported media formatsandroid

hope works :)


Comments

Popular posts from this blog

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -