/// <summary> /// Gets the episode location. /// </summary> /// <param name="episode">The episode to get the path for</param> /// <returns>The episode location.</returns> public static string GetEpisodeLocation(Episode episode) { char sep = Path.DirectorySeparatorChar; string ext = Path.GetExtension(episode.Url.ToString()); string subscriptionFolder = episode.Parent.Filename; string episodeName = episode.Filename; string externalStorage = Android.OS.Environment.ExternalStorageDirectory.ToString(); string appName = "Podcasts"; return externalStorage + sep + appName + sep + subscriptionFolder + sep + episodeName + ext; }
/// <summary> /// Pushs the updates. /// </summary> /// <param name='episode'>Episode.</param> public static void PushUpdates(Episode episode) { string json = JsonConvert.SerializeObject(episode); Uri location = new Uri(GPodderLocation + "/api/2/episodes/" + connectedUser.Username + JSONExtension); postData(location, GetBytes(json)); }
/// <summary> /// Ons the start. /// </summary> /// <param name='intent'> Intent.</param> /// <param name='startId'>Start identifier.</param> public override void OnStart(Intent intent, int startId) { base.OnStart(intent, startId); stop(); episode = EpisodeList.SelectedEpisode; player = MediaPlayer.Create(PortaPodderApp.Context, Android.Net.Uri.Parse(PortaPodderDataSource.GetEpisodeLocation(episode))); // set the player to update the episode current position whenever a seek operation is sent player.SeekComplete += delegate(object sender, EventArgs e) { episode.PlayerPosition = player.CurrentPosition; }; // there is not duration meta-data to be had in the gpodder data structures, so we need to determine it once the media player has // been created and set it at this time and then broadcast it episode.Duration = player.Duration; // go to the last recorded position and start playing from there player.SeekTo(episode.PlayerPosition); player.Start(); // the progress monitor is the background thread which is going to send broadcasts about how far along the player is progressMonitor.Stop = false; if(!progressMonitor.IsRunning) { progressMonitor.Execute(); } // now bind an incoming message reciever for operations IntentFilter intentToReceiveFilter = new IntentFilter(); intentToReceiveFilter.AddAction(PLAYER_INSTRUCTION_SEEK_RELATIVE_FORWARD); intentToReceiveFilter.AddAction(PLAYER_INSTRUCTION_SEEK_RELATIVE_BACKWARD); intentToReceiveFilter.AddAction(PLAYER_INSTRUCTION_SEEK_ABSOLUTE); this.RegisterReceiver(reciever, intentToReceiveFilter, null, handler); receiversRegistered = true; }
/// <summary> /// Cursors to episode. /// </summary> /// <returns>The to episode.</returns> /// <param name='cursor'>Cursor.</param> private Episode cursorToEpisode(ICursor cursor) { Episode episode = new Episode(); episode.Description = cursor.GetString(cursor.GetColumnIndex(Episode.COL_DESCRIPTION)); episode.MygpoLink = stringToUrl(cursor.GetString(cursor.GetColumnIndex(Episode.COL_MYGPO_LINK))); episode.PodcastTitle = cursor.GetString(cursor.GetColumnIndex(Episode.COL_PODCAST_TITLE)); episode.PodcastUrl = stringToUrl(cursor.GetString(cursor.GetColumnIndex(Episode.COL_PODCAST_URL))); episode.Released = DateTime.Parse(cursor.GetString(cursor.GetColumnIndex(Episode.COL_RELEASED))); episode.Status = (Episode.EpisodeStatus)Enum.Parse(typeof(Episode.EpisodeStatus), cursor.GetString(cursor.GetColumnIndex(Episode.COL_STATUS))); episode.Title = cursor.GetString(cursor.GetColumnIndex(Episode.COL_TITLE)); episode.Url = stringToUrl(cursor.GetString(cursor.GetColumnIndex(Episode.COL_URL))); episode.Website = stringToUrl(cursor.GetString(cursor.GetColumnIndex(Episode.COL_WEBSITE))); episode.PlayerPosition = cursor.GetInt(cursor.GetColumnIndex(Episode.COL_PLAYER_POSITION)); episode.Duration = cursor.GetInt(cursor.GetColumnIndex(Episode.COL_DURATION)); return episode; }
/// <summary> /// Creates the content values. /// </summary> /// <returns>The content values.</returns> /// <param name='episode'>Episode.</param> private ContentValues createContentValues(Episode episode) { ContentValues values = new ContentValues(); values.Put(Episode.COL_DESCRIPTION, episode.Description); values.Put(Episode.COL_MYGPO_LINK, episode.MygpoLink != null ? episode.MygpoLink.ToString() : string.Empty); values.Put(Episode.COL_PODCAST_TITLE, episode.PodcastTitle); values.Put(Episode.COL_PODCAST_URL, episode.PodcastTitle != null ? episode.PodcastUrl.ToString() : string.Empty); values.Put(Episode.COL_RELEASED, episode.Released.ToString()); values.Put(Episode.COL_STATUS, episode.Status.ToString()); values.Put(Episode.COL_TITLE, episode.Title); values.Put(Episode.COL_URL, episode.Url != null ? episode.Url.ToString() : string.Empty); values.Put(Episode.COL_WEBSITE, episode.Website != null ? episode.Website.ToString() : string.Empty); values.Put(Episode.COL_PLAYER_POSITION, episode.PlayerPosition); values.Put(Episode.COL_DURATION, episode.Duration); return values; }
/// <summary> /// Update the specified episode. /// </summary> /// <param name='episode'>Episode.</param> public void Update(Episode episode) { try{ dbHelper.WritableDatabase.Update(Episode.TABLE_NAME, createContentValues(episode), Episode.COL_URL + "=?", new string[]{episode.Url.ToString()}); } catch(Exception exc) { throw new Exception("Could not update episode " + episode.Url, exc); } }
/// <summary> /// Inserts the episode. /// </summary> /// <param name='episode'>Episode.</param> public bool InsertOrUpdate(Episode episode) { if(dbHelper == null || dbHelper.WritableDatabase == null || episode == null || episode.Url == null) { return false; } // attempt to query the database for this item ICursor cursor = dbHelper.WritableDatabase.Query(Episode.TABLE_NAME, null, Episode.COL_URL + " = ?", new string[]{episode.Url.ToString()}, null, null, null); if(cursor.Count > 0) { Update(episode); return false; } else { Insert(new List<Episode>(new Episode[]{episode})); return true; } }
/// <summary> /// Deletes the episode. /// </summary> /// <param name='episode'>Episode.</param> public void DeleteEpisode(Episode episode) { try { dbHelper.WritableDatabase.Delete(Episode.TABLE_NAME, Episode.COL_URL + "=?", new string[]{episode.Url.ToString()}); // now try to delete the file from the file system string path = GetEpisodeLocation(episode); if(File.Exists(path)){ File.Delete(path); } } catch(Exception exc) { throw new Exception("Could not delete episode " + episode.Url, exc); } }