<?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>
上面是我的XML文件我只是想用这个XML文件播放音乐假设我正在访问第0块应用程序播放song1.mp3如果我正在访问第1块应用程序播放song2.mp3等等...我麦芽汁像这样的功能......
android.view.View.OnClickListener spanish = new android.view.View.OnClickListener() {
public void onClick(View v) {
MediaPlayer m = MediaPlayer.create(Formulae.this, R.drawable.song1.mp3);
m.start();
}
};
上面的代码是静态的,我如何根据选定的块使其动态化(R.drawable.song1.mp3)......事情来自XML。请帮帮我谢谢。
答案 0 :(得分:1)
只是为了给你一个想法
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;
}
};
在Android上播放音频视频 - &gt; http://developer.android.com/guide/topics/media/index.html
在android上阅读xml文件 - &gt; http://developer.android.com/reference/org/xml/sax/package-summary.html
因为你知道你的建议使用xpath - &gt; http://developer.android.com/reference/javax/xml/xpath/package-summary.html
如果你不知道怎么放这个,你应该先学习oo编程和java!