开发者

How to recreate "Now Playing" button from iPod.app

My app has 4 Tabs and 3 of these Tabs also has navigation on top. I want to add a NowPlaying button to the top right of the navigation just like iPod.app. I have a class called SoundMachineViewController. This is where I have created my AVPlayer to play a remote mp3. If I went to one of my Tabs and selected a Track, my app would launch SoundMachine and starts playing the track. But if I decide to browse around, for example Tab3, I want to be able to go back to the currently playing track and rewind or something. I would click on the "Now Playing" button to get back to my SoundMachineViewController. But right now it would just create a new SoundMachine. Instead of going to the current one.

How do I keep the same currently playing track? I did some researc开发者_如何学运维h and I think singleton is the answer. But how do I go about converting my SoundMachineViewController to a singleton class? Can someone be kind enough to provide some code examples? Or at least explain the concept how on to accomplish my goal so I can research some more or try it out?

And would I just keep this action to my Now Playing button?

- (IBAction)ButtonClicked:(id)sender
{
    if (self.nowPlayingView == nil)
        self.nowPlayingView = [[[SoundMachineViewController alloc] initWithNibName:@"SoundMachineViewController" bundle:nil] autorelease];

 [self.navigationController presentModalViewController:self.nowPlayingView animated:YES];
}


A singleton could work for you, check out this post for the Singleton pattern implemented in Objective-C

What should my Objective-C singleton look like?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜