Note that there are some explanatory texts on larger screens.

plurals
  1. POandroid:play audio files and display images dynamically
    text
    copied!<p>Hi guys i am having 3 audio files and three images with three text displaying for each image. Now what i have done as soon as application starts the first image,text and audio file starts playing and after completion of that 2nd one starts similarly 3rd one starts.</p> <p>Basically i need these to played sequentially one after the other but dynamically since i am having some 20 files similar to this</p> <p>below is my code</p> <pre><code>public class S001Activity extends Activity { /** Called when the activity is first created. */ ImageView img; TextView display; MediaPlayer apple = new MediaPlayer(); MediaPlayer boy = new MediaPlayer(); MediaPlayer cat = new MediaPlayer(); //Runnable rb,rc; Document doc; DocumentBuilder builder; Handler handler = new Handler(); int i=0; int noOfQues = 0; //int media[] = {R.raw.apple_v,R.raw.boy_v,R.raw.cat_v}; //int image[] = {R.drawable.apple,R.drawable.boy,R.drawable.cat}; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); img = (ImageView)findViewById(R.id.img); display = (TextView)findViewById(R.id.display); img.setBackgroundResource(R.drawable.apple); apple = MediaPlayer.create(this, R.raw.apple_v); apple.start(); xml(); boy = MediaPlayer.create(this, R.raw.boy_v); handler.postDelayed(new Runnable() { @Override public void run() { // TODO Auto-generated method stub i++; img.setBackgroundResource(R.drawable.boy); boy.start(); xml(); } },apple.getDuration()+ 2000 ); cat = MediaPlayer.create(this, R.raw.cat_v); handler.postDelayed(new Runnable() { @Override public void run() { // TODO Auto-generated method stub i++; img.setBackgroundResource(R.drawable.cat); cat.start(); xml(); } },apple.getDuration()+ boy.getDuration()+ 2000 ); } public void xml(){ try { InputStream in = getResources().openRawResource(R.raw.topic1761); builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); doc = builder.parse(in, null); NodeList listOfPersons = doc.getElementsByTagName("Point"); noOfQues = listOfPersons.getLength(); System.out.println("items======= " + noOfQues); Node firstPersonNode = listOfPersons.item(i); Element firstPersonElement = (Element) firstPersonNode; NodeList firstNameList = firstPersonElement.getElementsByTagName("PracticeText"); Element firstNameElement = (Element) firstNameList.item(0); NodeList textFNList = firstNameElement.getChildNodes(); display.setText(((Node) textFNList.item(0)).getNodeValue().trim()); } catch (Throwable t) { Toast.makeText(this, "Exception: " + t.toString(), 2000).show(); } } </code></pre> <p>edited code</p> <pre><code>@Override public void onCompletion(MediaPlayer mps) { // TODO Auto-generated method stub //MediaPlayer mps = new MediaPlayer(); img.setBackgroundResource(image[i]); handler.post(new Runnable() { @Override public void run() { xml(); AssetFileDescriptor afd = getResources().openRawResourceFd(media[i]); mp.reset(); try { mp.setDataSource(afd.getFileDescriptor()); afd.close(); mp.prepare(); mp.start(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload