public override void ViewWillAppear(bool animated) { base.ViewWillAppear (animated); // This is not double loading becuase it is a new _loader each time and the _newSL is a get set _loader = new List<SongToSave> (); _dbWorker = new DBWorker (); _dbWorker.StartDBWorker (); dbPath = _dbWorker.GetPathToDb (); var conn = new SQLiteConnection (dbPath); // this seems redundant. foreach (var item in conn.Table<SongToSave>()) { var tempSong = new SongToSave () { BookTitle = item.BookTitle, BookAuthor = item.BookAuthor, PlayPosition = item.PlayPosition }; _loader.Add (tempSong); } conn.Close (); // why am I using two list? _newSL = _loader; TableView.ReloadData (); }
public BookShelfTable() { _dbWorker = new DBWorker (); _dbWorker.StartDBWorker (); dbPath = _dbWorker.GetPathToDb (); Console.WriteLine ("Constructor Ran"); }
public void ResumeBook(string titleToResume, string resumingAuthor) { string chosenTitle = titleToResume; double aVeryGoodPlaceToStart = 0; dbWorker = new DBWorker (); dbWorker.StartDBWorker (); dbPath = dbWorker.GetPathToDb (); var conn = new SQLiteConnection (dbPath, false); var resumeQuery = conn.Table<SongToSave> ().Where (q => q.BookTitle == chosenTitle); foreach (var result in resumeQuery) { aVeryGoodPlaceToStart = result.PlayPosition - 30; } ResumePointVault = aVeryGoodPlaceToStart; _mediaQuery = new MPMediaQuery (); var value = NSNumber.FromInt32 ((int)MPMediaType.Music); //type of media to return var property = MPMediaItem.MediaTypeProperty; var predicate = MPMediaPropertyPredicate.PredicateWithValue (value, property); _mediaQuery.AddFilterPredicate (predicate); var valueTwo = NSString.FromObject ((String)chosenTitle); var propertyTwo = MPMediaItem.TitleProperty; var predicateTwo = MPMediaPropertyPredicate.PredicateWithValue (valueTwo, propertyTwo); _mediaQuery.AddFilterPredicate (predicateTwo); _musicPlayer = new MPMusicPlayerController (); // volume is dicpercated in ios7 _musicPlayer.SetQueue (_mediaQuery); _musicPlayer.CurrentPlaybackTime = aVeryGoodPlaceToStart; Console.WriteLine ("afterQueSet: {0}", _musicPlayer.CurrentPlaybackTime); positionSkipBtn.Enabled = true; // set the end file length double fileLengthRaw = _musicPlayer.NowPlayingItem.PlaybackDuration; int fileLengthInt = Convert.ToInt32 (fileLengthRaw); string fileLengthDisplay = string.Format ("{0:##}:{1:00}:{2:00}", fileLengthInt / 3600, (fileLengthInt / 60) % 60, fileLengthInt % 60); lengthLbl.Text = fileLengthDisplay; int startingPlaceInt = Convert.ToInt32 (aVeryGoodPlaceToStart); string aVeryGoodPlaceToStartDisplay = string.Format("{0:#0}:{1:00}:{2:00}",startingPlaceInt/3600,(startingPlaceInt/60)%60,startingPlaceInt%60); currentTimeLbl.Text = aVeryGoodPlaceToStartDisplay; Console.WriteLine ("resume point: {0}", aVeryGoodPlaceToStart); // debugging positionSld.MaxValue = (float)(fileLengthRaw); positionSld.SetValue ((float)(aVeryGoodPlaceToStart), true); titleLbl.Text = chosenTitle; artistLbl.Text = resumingAuthor; playPauseBtn.Enabled = true; Console.WriteLine ("ran righ over it"); // debugging Console.WriteLine ("attheresumeend: {0}", _musicPlayer.CurrentPlaybackTime); }
public void Stopper() { Console.WriteLine ("Test point one"); dbWorker = new DBWorker (); dbWorker.StartDBWorker (); dbPath = dbWorker.GetPathToDb (); var conn = new SQLiteConnection (dbPath); // this playingstate shit is not working right? var playerState = _musicPlayer.PlaybackState; if (playerState == MPMusicPlaybackState.Playing || playerState == MPMusicPlaybackState.Paused){ // need to disable the play buttons and change the title/artist text to null Console.WriteLine ("Test point two"); playPauseBtn.Enabled = false; stopBtn.Enabled = false; positionSkipBtn.Enabled = false; timerBtn.Enabled = false; titleLbl.Text = "Song Not Selected"; artistLbl.Text = "Artist Not Available"; currentTimeLbl.Text = "0:00:00"; lengthLbl.Text = "0:00:00"; positionSld.SetValue(0f, false); Console.WriteLine("music was playing or paused"); // debugging refreshTimer.Invalidate(); PlayPauseSwitch = "play"; string stopTitle = _musicPlayer.NowPlayingItem.Title; string authorChecker = _musicPlayer.NowPlayingItem.Artist; string stopAuthor = " "; if (authorChecker == null || authorChecker.Length < 1) { stopAuthor = "No Artist"; } else{ stopAuthor = authorChecker; } Console.WriteLine("Author Saving: " + stopAuthor); // debugging double startingPoint = _musicPlayer.CurrentPlaybackTime; Console.WriteLine ("Stopping point: {0}", startingPoint); var query = conn.Table<SongToSave>().Where(q => q.BookTitle == stopTitle); SongToSave sts; if (query.Count() > 1){ Console.WriteLine("We have a problem, more than one book stored"); // debugging } else if (query.Count() > 0){ // replace the entry foreach (var item in query){ sts = new SongToSave() {BookTitle = stopTitle, BookAuthor = stopAuthor, PlayPosition = startingPoint, ID = item.ID}; conn.Update(sts); } } else{ sts = new SongToSave() {BookTitle = stopTitle, PlayPosition = startingPoint}; conn.Insert(sts); } _musicPlayer.Stop(); UIAlertView alert = new UIAlertView("Position Saved", stopTitle, null, "OK", null); alert.Show(); } else{ Console.WriteLine("Stopped Nothing"); //debugging return; } }