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 9103039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:32:06+00:00 2026-06-17T01:32:06+00:00

I have playlists songs in NSArray and show that songs in my UITableView like

  • 0

I have playlists songs in NSArray and show that songs in my UITableView like following pic.

enter image description here

In my case, when i select one song from UITableView , i want to play that song with MPMusicPlayerController's applicationMusicPlayer.

I mean when i select american idiot from UITableView , i want to play American idiot with MPMusicPlayerController's

And when i tap below Skip button , it’s must be play next song like jesus of suburbia.

Here is my code that load songs to UITableView

self.player = [MPMusicPlayerController applicationMusicPlayer];

    MPMediaQuery *query = [MPMediaQuery playlistsQuery];
    MPMediaPredicate *predicate = [MPMediaPropertyPredicate predicateWithValue:@"GreenDay" forProperty:MPMediaPlaylistPropertyName comparisonType:MPMediaPredicateComparisonContains];

    [query addFilterPredicate:predicate];

    self.arrayOfSongs = [query items];

i think you understand what i mean.
I want to do all music button work like iOS build in Music app and play song when i select song from UITableView.

I am trying anyting , but i didn’t find solutions that can solve my problem.

Please help me to do like that.

Thanks you. 🙂

  • 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-06-17T01:32:08+00:00Added an answer on June 17, 2026 at 1:32 am

    Assuming that your NSArray was populated with MPMediaItems from a MPMediaItemCollection, this is actually fairly simple once you know what you need to configure. First, create a iVar, preferably NSUInteger to store the index of the currently playing track. This will be necessary to go from one track to another in order.

    Second, it’s hard to tell from your post wether the track titles are being read from the media items in the collections or are if they’re just statically placed on the table, but I’ve included an example of how to read a track title from the media items in the array and set that value as the cells text using valueForProperty.

    And finally, didSelectRowAtIndexPath is configured below to demonstrate of the set the unsigned integer that you’ve already created to the value of the selected cell. Both didSelectRowAtIndexPath and the two IBActions I’ve created both modify the value of this index and then call the void I’ve created “stopCurrentTrackAndPlaySelection” which stops the currently playing track, typecasts MPMediaItem to the object at that index, and then starts playing again.

    If you need more clarification just ask 🙂

    Side note: I recommend that you store a copy of the media pickers selection (MPMediaItemCollection) in a NSMutableArray instead of NSArray, or MPMediaItemCollection directly. This will allow you to add or remove tracks on the fly without having to stop playback.

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return [myArrayOfTracks count];
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CellIdentifier = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        }
        [[cell textLabel] setText:[(MPMediaItem *)[myArrayOfTracks objectAtIndex:indexPath.row] valueForProperty:MPMediaItemPropertyTitle]];
    
        return cell;
    }
    
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        indexOfCurrentlyPlayingTrack = indexPath.row;
        [self stopCurrentTrackAndPlaySelection];
    }
    
    - (IBAction)nextTrack:(UIButton *)sender
    {
        indexOfCurrentlyPlayingTrack ++;
        [self stopCurrentTrackAndPlaySelection];
    }
    
    - (IBAction)previousTrack:(UIButton *)sender
    {
        indexOfCurrentlyPlayingTrack --;
        [self stopCurrentTrackAndPlaySelection];
    }
    
    - (void)stopCurrentTrackAndPlaySelection
    {
        [myMPMusicPlayerController stop];
        [myMPMusicPlayerController setNowPlayingItem:(MPMediaItem *)[myArrayOfTracks objectAtIndex:indexOfCurrentlyPlayingTrack]];
        [myMPMusicPlayerController play];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML file that looks like <?xml version=1.0> <playlist> <name>My Playlist</name> <song>
I did the following script in order to identify itunes songs that doesn't have
I have a page written in PHP that has a playlist of songs. When
I have a model called Playlists which has_and_belongs_to_many :songs In my PlaylistController I call
I have a ListView that contains playlists. If the user wants to edit an
I have the following models: User Playlist SongLike Song ... When I query a
I have created an XSPF playlist of songs that I need to copy to
I'm having trouble with the following: I have a spinner with different songs in
I have a project that is like an IPOD playlist . Im having trouble
I have a page that loads a playlist of songs. The individual songs in

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.