Answer the question
In order to leave comments, you need to log in
How to play an audio file for a ViewPager page?
The ViewPager shows a series of images that are swiped through. How can I "attach" automatic playback of an audio file to each image? Each picture has its own audio file. Here is the adapter code:
public class CustomSwipeAdapter extends PagerAdapter {
private int[] image_resourses = {
R.drawable.eskiz_1, R.drawable.eskiz_2,
R.drawable.eskiz_3, R.drawable.eskiz_4};
private Context ctx;
private LayoutInflater layoutInflatter;
public CustomSwipeAdapter (Context ctx){
this.ctx = ctx;
}
@Override
public int getCount() {
return image_resourses.length;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return (view==(LinearLayout)object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
layoutInflatter = (LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View item_view = layoutInflatter.inflate(R.layout.swipe_layout,container,false);
ImageView imageView = (ImageView)item_view.findViewById(R.id.image_view);
imageView.setImageResource(image_resourses[position]);
container.addView(item_view);
return item_view;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((LinearLayout)object);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question