Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6757169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:36:50+00:00 2026-05-26T13:36:50+00:00

I am trying to make an app that plays MP3 songs. My program flow

  • 0

I am trying to make an app that plays MP3 songs. My program flow is like this:

I have an XML file here in my website: http://jeewanaryal.web44.net/SongsXML/songsListXML.xml. It has song titles and the actual URL of those songs on the Internet. I have the following code for my Pop songs section:

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];

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.

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:36:51+00:00Added an answer on May 26, 2026 at 1:36 pm

    You would need to store arrayOfSongs somewhere in the class. The “back” and “next” buttons would need separate actions (e.g. playPreviousSong, playNextSong). These methods would then look something like this:

    -(void) playPreviousSong
    {
        NSString *url = [[self songs] objectAtIndex:[self songIndex] - 1];
        [self playSong:url];
        [self setSongIndex:[self songIndex - 1];
    }
    

    This is a crude implementation just to show how it’d fit together. Basically you need to store the list of songs and keep track of which song is “selected”/playing, then just select the next/previous one.

    Edit: To answer your question in the comments, you have already extracted the array of song URLs, you simply need to keep a reference to it in the class. E.g.

    @interface AudioPlayer {
        NSArray *_songs;
        NSUInteger *_songIndex;
    }
    

    Then in the @implementation instead of creating a arrayOfSongs variable, simply reference the array from the instance variable:

    _songs = [[NSArray alloc] initWithArray:[[[dict objectForKey:@"list"] objectForKey:@"songs"] objectForKey:@"song"]];
    

    Then in, for example, the playPreviousSong method:

    -(void) playPreviousSong
    {
        NSString *url = [_songs objectAtIndex:_songIndex - 1];
        [self playSong:url];
        _songIndex--;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to make a small app in c++ that saves midifiles with this
I am trying to make an app that will have multiple screens, and I
I'm trying to make photo album like photo.app in iPhone. I know We have
I have an app that I am trying to make more tablet compatible. In
I am trying to make an app that will pass data between two servers
I'm trying to make a console app that would monitor some process and restart
I'm trying to make a simple app that sits on the Mac OSX menu
I am trying to make a web app in Dashcode that uses a range
I have an app with tabbar and webview. I'm trying to make the app
I'm trying to make a HTML5 webapp that simply plays a sound over and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.