// Set up the table view cells public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) { UITableViewCell cell = TableView.DequeueReusableCell("cell"); if (cell == null) { cell = new UITableViewCell(UITableViewCellStyle.Subtitle, "cell"); } if (loading) { cell.TextLabel.Text = "Loading..."; cell.DetailTextLabel.Text = "This may take a bit for a large library"; } else { Song song = Songs.GetSongBySectionRow(indexPath.Section, indexPath.Row); cell.TextLabel.Text = song.song; cell.TextLabel.Font = UIFont.PreferredBody; cell.DetailTextLabel.Text = String.Format("Album: {0}", song.album); if (song == MyMusicPlayer.GetInstance().currentSong) { cell.BackgroundColor = UIColor.FromRGB(0.9f, 0.9f, 0.9f); } else { cell.BackgroundColor = UIColor.White; } } return(cell); }
// Get ready to segue to the detail view controller public override void PrepareForSegue(UIStoryboardSegue segue, NSObject sender) { // The segue to use if (segue.Identifier == "showDetail") { detailViewController = segue.DestinationViewController as DetailViewController; if (sender == leftBBI) { Song song = Songs.GetStreamingSongByIndex(0); // Pass song info to the detail view controller detailViewController.song = song; } else if (sender == rightBBI) { Song playingSong = MyMusicPlayer.GetInstance().currentSong; detailViewController.song = playingSong; } else { // Selected song NSIndexPath indexPath = Songs.searching ? searchController.SearchResultsTableView.IndexPathForSelectedRow : TableView.IndexPathForSelectedRow; Song song = Songs.GetSongBySectionRow(indexPath.Section, indexPath.Row); song.streamingURL = null; // Pass song info to the detail view controller detailViewController.song = song; } } }
public static MyMusicPlayer GetInstance() { if (MyMusicPlayer.myMusicPlayer == null) { MyMusicPlayer.myMusicPlayer = new MyMusicPlayer(); } return(MyMusicPlayer.myMusicPlayer); }
public void NowPlaying(UIBarButtonItem sender) { if (MyMusicPlayer.GetInstance().currentSong != null) { PerformSegue("showDetail", sender); } else { UIAlertController ac = UIAlertController.Create("No songs playing", "Please select a song to play", UIAlertControllerStyle.Alert); UIAlertAction defaultAction = UIAlertAction.Create("OK", UIAlertActionStyle.Cancel, null); ac.AddAction(defaultAction); PresentViewController(ac, true, null); } }
public override void ViewDidLoad() { base.ViewDidLoad(); // Create and initialize music player musicPlayer = MyMusicPlayer.GetInstance(); musicPlayer.EndReached -= MusicPlayer_PlayNextSong; musicPlayer.StartReached -= MusicPlayer_PlayPrevSong; musicPlayer.ReadyToPlay -= MusicPlayer_EnablePlayPauseButton; musicPlayer.EndReached += MusicPlayer_PlayNextSong; musicPlayer.StartReached += MusicPlayer_PlayPrevSong; musicPlayer.ReadyToPlay += MusicPlayer_EnablePlayPauseButton; // set up handler for when app resumes from background NSNotificationCenter.DefaultCenter.AddObserver(this, new Selector("resumeFromBackground"), UIApplication.DidBecomeActiveNotification, null); // Register for receiving controls from lock screen and controlscreen UIApplication.SharedApplication.BeginReceivingRemoteControlEvents(); }