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

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -