Audio is not in sync with images using Viewpager -
i creating simple android app. used code images , sound etc works fine audio not in pattern(sync) according images. according sound image 1 step next means example ant bee sound plays , want play ant sound ant , bee fee using same array index of images , audios nothing works. here code mainactivity.java
package com.example.zeeshanm.ibrahim; import android.media.mediaplayer; import android.os.bundle; import android.app.activity; import android.content.context; import android.support.v4.view.pageradapter; import android.support.v4.view.viewpager; import android.util.log; import android.view.view; import android.view.viewgroup; import android.widget.imageview; import android.widget.toast; public class mainactivity extends activity { public mediaplayer mp; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); viewpager viewpager = (viewpager)findviewbyid(r.id.myfivepanelpager); imagepageradapter adapter = new imagepageradapter(); viewpager.setadapter(adapter); } private class imagepageradapter extends pageradapter { private int[] mimages = new int[] {r.drawable.ant,r.drawable.bee, r.drawable.cat,r.drawable.dog,r.drawable.duck,r.drawable.elephant, r.drawable.frog,r.drawable.giraffe,r.drawable.horse,r.drawable.iguana,r.drawable.jaguar,r.drawable.koala, r.drawable.lion,r.drawable.monkey,r.drawable.numbat,r.drawable.owl,r.drawable.panda,r.drawable.parrot, r.drawable.quoll,r.drawable.rabbit,r.drawable.seal,r.drawable.snack,r.drawable.tiger,r.drawable.uracca, r.drawable.vampirebat,r.drawable.wombat,r.drawable.xenops,r.drawable.yacare,r.drawable.zebra}; private int[] maudio= new int[]{r.raw.hormiga_ant_en,r.raw.abeja_bee_en,r.raw.shout_jaguar, r.raw.shout_perro_dog,r.raw.pato_duck_en, r.raw.elefante_elephant_en,r.raw.shout_rana_frog,r.raw.jirafa_giraffe_en, r.raw.shout_caballo_horse,r.raw.iguana_en,r.raw.jaguar_en,r.raw.shout_koala,r.raw.leon_lion_en, r.raw.shout_mono_monkey, r.raw.numbat_en,r.raw.shout_buho_owl,r.raw.shout_oso_bear, r.raw.shout_zorro_fox,r.raw.quoll_en,r.raw.conejo_rabbit_en,r.raw.shout_foca_seal, r.raw.shout_serpiente_snake, r.raw.tigre_tiger_en,r.raw.shout_urraca,r.raw.murcielago_vampirebat_en, r.raw.shout_murcielago_vampirebat,r.raw.xenops_en,r.raw.shout_yacare,r.raw.shout_cebra_zebra}; @override public int getcount() { return mimages.length; } @override public boolean isviewfromobject(view view, object object) { return view == ((imageview) object); } @override public object instantiateitem(viewgroup container, int position) { context context = mainactivity.this; imageview imageview = new imageview(context); int padding =context.getresources(). getdimensionpixelsize(r.dimen.activity_vertical_margin); imageview.setpadding(padding, padding, padding, padding); imageview.setscaletype(imageview.scaletype.fit_xy); imageview.setimageresource(mimages[position]); ((viewpager) container).addview(imageview, 0); //for sound if (mp != null) { mp.reset(); mp.release(); } mp = mediaplayer.create(mainactivity.this, maudio[position]); toast.maketext(mainactivity.this, "position " + maudio[position] + " , " + mimages[position], toast.length_short); mp.start(); return imageview; } @override public void destroyitem(viewgroup container, int position, object object) { ((viewpager) container).removeview((imageview) object); } }
}
Comments
Post a Comment