<?xml version="1.0" encoding="utf-8"?>
<!-- generator="FeedCreator 1.7.2"-->
<rss version="2.0">
<strings>
<level>one</level>
</strings>
<item>
<contentitem>
<title>Song 1</title>
<view>Song 1</view>
<english>Song1.mp3</english>
</contentitem>
</item>
<item>
<contentitem>
<title>Song 2</title>
<view>Song 2</view>
<english>song2.mp3</english>
</contentitem>
</item>
<item>
<contentitem>
<title>Song 3</title>
<view>Song 3</view>
<english>song3.png</english>
<spanish>song3.png</spanish>
</contentitem>
</item>
<item>
<contentitem>
<title>Song 4</title>
<view>Song 4</view>
<english>song4.mp3</english>
<spanish>song4.mp3</spanish>
</contentitem>
</item>
</rss>
Above is mine XML file I just want to play music using this XML file suppose I am visiting the 0th block App play song1.mp3 if I am visiting the 1st block App play song2.mp3 and so on... I wort the function like this....
android.view.View.OnClickListener spanish = new android.view.View.OnClickListener() {
public void onClick(View v) {
开发者_JAVA技巧 MediaPlayer m = MediaPlayer.create(Formulae.this, R.drawable.song1.mp3);
m.start();
}
};
Above code is static how can I make it dynamic (R.drawable.song1.mp3) according to selected block...and things comes form the XML. Please help me out Thank you.
just to give you the idea
android.view.View.OnClickListener spanish = new android.view.View.OnClickListener() {
MediaPlayer mediaPlayer;
public void onClick(View v) {
// we want to create the mediaPlayer Instance
// just once
if(mediaPlayer==null)
mediaPlayer = new MediaPlayer();
// try getting the new Title that should be played
String pathToNewTitle = getPathFromClickedViewItem(v);
// stop current Song
mediaPlayer.stop();
try {
mediaPlayer.setDataSource();
} catch (IllegalArgumentException e1) {
// implement this yourself
} catch (IOException e2) {
// implement this yourself
}
mediaPlayer.start();
}
private String getPathFromClickedViewItem(View v) {
String path;
// you have to implement this yourself
// the idea is to determine the path
// for the mp3 that should be played
// when a specific view item is clicked
return path;
}
};
playing audio video on android -> http://developer.android.com/guide/topics/media/index.html
reading a xml file on android -> http://developer.android.com/reference/org/xml/sax/package-summary.html
since you know your i'd suggest using xpath -> http://developer.android.com/reference/javax/xml/xpath/package-summary.html
if you don't know how to put this togehter, you should first learn oo-programming and java!
精彩评论