Note that there are some explanatory texts on larger screens.

plurals
  1. PODifficulty with accessing list of URLs in XML file
    text
    copied!<p>I am trying to make an app that plays MP3 songs. My program flow is like this:</p> <p>I have an XML file here in my website: <a href="http://jeewanaryal.web44.net/SongsXML/songsListXML.xml" rel="nofollow">http://jeewanaryal.web44.net/SongsXML/songsListXML.xml</a>. It has song titles and the actual URL of those songs on the Internet. I have the following code for my Pop songs section:</p> <pre><code>NSString *urlString = @"http://jeewanaryal.web44.net/SongsXML/songsListXML.xml"; NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlString]]; NSDictionary *dict = [XMLReader dictionaryForXMLData:data error:nil]; NSArray *arrayOfSongs = [[NSArray alloc] initWithArray:[[[dict objectForKey:@"list"] objectForKey:@"songs"] objectForKey:@"song"]]; StartStopSound = [UIButton buttonWithType:UIButtonTypeRoundedRect]; StartStopSound.frame = CGRectMake(60, 360, 200, 30); [StartStopSound setTitle:@"बजाउनुहोस" forState:UIControlStateNormal]; [StartStopSound addTarget:self action:@selector(playSong) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:StartStopSound]; back = [UIButton buttonWithType:UIButtonTypeRoundedRect]; back.frame = CGRectMake(20, 320, 100, 30); [back setTitle:@"पछाडीको गीत " forState:UIControlStateNormal]; [back addTarget:self action:@selector(playSong) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:back]; next = [UIButton buttonWithType:UIButtonTypeRoundedRect]; next.frame = CGRectMake(200, 320, 100, 30); [next setTitle:@"अगाडीको गीत" forState:UIControlStateNormal]; [next addTarget:self action:@selector(playSong) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:next]; NSData *myData = [[NSData alloc] init ]; NSString *urlString1 = [[NSString alloc] init]; for (NSDictionary *fruitDict in arrayOfSongs) { UILabel *songTitle = [[UILabel alloc] initWithFrame:CGRectMake(40, 200, 300, 40)]; songTitle.text = [NSString stringWithFormat:@"%@",[[fruitDict objectForKey:@"title"] objectForKey:@"text"]]; [self.view addSubview:songTitle]; urlString1 = [NSString stringWithFormat:@"%@",[[fruitDict objectForKey:@"url"] objectForKey:@"text"]]; //NSLog(@"\n\n -- URL STRING : %@ \n\n",urlString); } myData = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlString1]]; player = [[AVAudioPlayer alloc] initWithData:myData error:nil]; [player play]; [player numberOfLoops]; [player currentTime]; </code></pre> <p>This works fine for a single song; that is, it only plays the last URL of my XML file. I want to make all songs to be played one by one, making a "Next" and "Previous" button on my app.</p> <p>Will you please tell me how I can implement that? I am using XMLReader.h and XMLReader.m file to parse the data from XML into my app.</p>
 

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