iTunes チャートへのリンク:
曲のタイトル、アルバム イメージへのリンク、および曲の Web リンクがリスト ビューに表示されます。
static final String KEY_ENTRY = "entry";
static final String KEY_TITLE = "title";
static final String KEY_TITLE_URL = "id";
static final String KEY_SONG_DOWNLOAD_URL = "link";
static final String KEY_ALBUM_IMAGE_URL = "im:image";
public static List<iTunes> getStackSitesFromFile(Context ctx) {
// List of StackSites that we will return
List<iTunes> itunes;
itunes = new ArrayList<iTunes>();
// temp holder for current StackSite while parsing
iTunes curiTunes = null;
// temp holder for current text value while parsing
String curText = "";
try {
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
XmlPullParser xpp = factory.newPullParser();
FileInputStream fis = ctx.openFileInput("iTunes.xml");
BufferedReader reader = new BufferedReader(new InputStreamReader(
fis));
xpp.setInput(reader);
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
String tagname = xpp.getName();
switch (eventType) {
case XmlPullParser.START_TAG:
if (tagname.equalsIgnoreCase(KEY_ENTRY)) {
curiTunes = new iTunes();
}
break;
case XmlPullParser.TEXT:
curText = xpp.getText();
break;
case XmlPullParser.END_TAG:
if (tagname.equalsIgnoreCase(KEY_ENTRY)) {
itunes.add(curiTunes);
} else if (tagname.equalsIgnoreCase(KEY_TITLE)) {
curiTunes.setTitle(curText);
} else if (tagname.equalsIgnoreCase(KEY_TITLE_URL)) {
curiTunes.setSongUrl(curText);
} else if (tagname.equalsIgnoreCase(KEY_SONG_DOWNLOAD_URL)) {
curiTunes.setSongDownloadUrl(curText);
} else if (tagname.equalsIgnoreCase(KEY_ALBUM_IMAGE_URL)) {
curiTunes.setAlbumImgUrl(curText);
}
break;
default:
break;
}
eventType = xpp.next();
}
} catch (Exception e) {
e.printStackTrace();
}
return itunes;
}
}