Mycah Mycah - 1 year ago 63
Android Question

Trying to pull and play an mp3 file from RSS feed in android app

I'm trying to make an app for a podcast. My end goal is for a user to be able to click on an episode in a list (which is generated from an RSS feed) and then have the audio play (which is also retrieved from the RSS feed) My problem is with parsing the XML from the RSS feed. I can't seem to figure out how to get the URL out of the enclosure tag for the mp3. Any help would be appreciated. Here is my parsing class

private String data;
private ArrayList<Episodes> mEpisodes;

public ParseEpisodes(String xmlData) { = xmlData;
mEpisodes = new ArrayList<>();

public ArrayList<Episodes> getEpisodes() {
return mEpisodes;

public boolean process(){
boolean status = true;
Episodes currentRecord = null;
boolean inEntry = false;
String textValue = "";
String urlValue = "";

XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
XmlPullParser xpp = factory.newPullParser();
xpp.setInput(new StringReader(;
int eventType = xpp.getEventType();

while(eventType != XmlPullParser.END_DOCUMENT){
String tagName = xpp.getName();
case XmlPullParser.START_TAG:
//Log.d("ParseEpisodes", "Starting tag for " + tagName);
inEntry = true;
currentRecord = new Episodes();

case XmlPullParser.TEXT:
textValue = xpp.getText();
urlValue = xpp.getText();

case XmlPullParser.END_TAG:
//Log.d("ParseEpisodes", "Ending tag for " + tagName);
inEntry = false;
}else if(tagName.equalsIgnoreCase("title")){
}else if(tagName.equalsIgnoreCase("enclosure")){

eventType =;

}catch (Exception e){
status = false;

return true;


here is the xml

<title>Episode 52 - Facebook Nukes The Show</title>
<enclosure url="" length="43312404" type="audio/mpeg"/>
<pubDate>Fri, 15 Jul 2016 15:22:24 -0700</pubDate>
<source url="">The GR3YNOISE Podcast</source>
<itunes:subtitle>Episode 52 - Facebook Nukes The Show</itunes:subtitle>
<itunes:summary>Episode 52 - Facebook Nukes The Show</itunes:summary>
<content:encoded><![CDATA[Episode 52 - Facebook Nukes The Show"}]]></content:encoded>

Answer Source

The solution to this ended up being pretty simple. All I needed to do was delete

urlValue = xpp.getText();

from the

case XmlPullParser.TEXT:

Then change

else if(tagName.equalsIgnoreCase("enclosure")){
         urlValue = xpp.getAttributeValue(0);

in the

case XmlPullParser.END_TAG:
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download