Question

I am developing a small music application in which first view comprises of all the List of songs in Tableview and when user taps on any one row (song) it takes them to Second view & Plays the song their(comprising of play/Pause Buttons). Now I go back in First View from Second View using back button to select another song. And their is one button in First View for just switching views(i.e it takes to current playing song)but it plays that same song from start but not from its currentplaying . Its similar to now Playing button in Stock Music app in iOS. Im using storyboards & Segues

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
temp = indexPath.row;
[tableView deselectRowAtIndexPath:indexPath animated:NO];
[self performSegueWithIdentifier:@"Player" sender:self];

}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
 if([[segue identifier] isEqualToString:@"Player"])
  {

    MPMediaItem *item = [itemCollections objectAtIndex:temp];
    NSString *trackInfo = [[NSString alloc] initWithFormat:@"%@- %@",[item   valueForProperty:MPMediaItemPropertyTitle],[item valueForProperty:MPMediaItemPropertyArtist]];
    MPMediaItemArtwork *artwork = [item valueForProperty:MPMediaItemPropertyArtwork];
    NSURL *tempURL = [item valueForProperty:MPMediaItemPropertyAssetURL];
    playerController = [segue destinationViewController];
    playerController.fileUrl1 = tempURL;
    playerController.globalVar = [NSNumber numberWithInteger:temp];
    playerController.labelTitleString = trackInfo;
    playerController.img = [artwork imageWithSize:CGSizeMake(100, 100)];

}

}

Was it helpful?

Solution

You could go about this in many ways -- I would suggest implementing a singleton to handle the media playback. Rather than constantly retaining that view, this singleton manager (part of your model) should provide any controllers with the needed information about the current song, album, author, etc.

Ex. In your TableViewController:

- (void)viewDidLoad
{
    [self setSong:[[PlaybackManager sharedInstance] currentSong]];
    if (self.song) {
        //Add navigation item
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top