android - Playing sound when ViewPager is swiped -
this question has answer here:
- want play sound on viewpager swipe 1 answer
how can play sound when viewpager swiped? should put player code? code use playing sound sample follows:
mediaplayer mp; mp = mediaplayer.create(context, r.raw.sample); mp.setoncompletionlistener(new mediaplayer.oncompletionlistener() { @override public void oncompletion(mediaplayer mp) { // todo auto-generated method stub mp.reset(); mp.release(); mp=null; } }); mp.start();
where should put player code?
viewpager
gives possibility register instance of class extends interface onpagechangelistener
, contains 3 callbacks:
onpagescrollstatechanged(int state)
onpagescrolled(int position, float positionoffset, int positionoffsetpixels)
onpageselected(int position)
you run when onpageselected
invoked
Comments
Post a Comment