private IMediaSource CreateCacheMediaSource(IMediaSource videoSource, Uri videoUrL) { try { if (PlayerSettings.EnableOfflineMode) { //Set the VideoObject for offline mode if (!string.IsNullOrEmpty(VideoData.VideoId)) { var file = VideoDownloadAsyncController.GetDownloadedDiskVideoUri(VideoData.VideoId); SimpleCache cache = new SimpleCache(ActivityContext.CacheDir, new LeastRecentlyUsedCacheEvictor(1024 * 1024 * 10)); CacheDataSourceFactory cacheDataSource = new CacheDataSourceFactory(cache, DefaultDataMediaFactory); if (!string.IsNullOrEmpty(file)) { videoUrL = Uri.Parse(file); videoSource = GetMediaSourceFromUrl(videoUrL, "normal"); return(videoSource); } else { return(null); } } else { return(null); } } else { return(null); } } catch (Exception exception) { Console.WriteLine(exception); return(null); } }
//Download public void Download_icon_Click(object sender, EventArgs e) { try { if (DownloadIcon.Tag.ToString() == "false") { DownloadIcon.SetImageResource(Resource.Drawable.ic_action_download_stop); DownloadIcon.Tag = "true"; if (VideoData.VideoLocation.Contains("youtube") || VideoData.VideoType.Contains("Youtube") || VideoData.VideoType.Contains("youtu")) { var urlVideo = VideoInfoRetriever.VideoDownloadstring; if (!string.IsNullOrEmpty(urlVideo)) { VideoControllers = new VideoDownloadAsyncController(urlVideo, VideoData.VideoId, ActivityContext, ActivityName); if (!VideoControllers.CheckDownloadLinkIfExits()) { VideoControllers.StartDownloadManager(VideoData.Title, VideoData, ActivityName); } } else { Methods.DialogPopup.InvokeAndShowDialog(ActivityContext, ActivityContext.GetText(Resource.String.Lbl_Error), ActivityContext.GetText(Resource.String.Lbl_You_can_not_Download_video), ActivityContext.GetText(Resource.String.Lbl_Ok)); } } else { VideoControllers = new VideoDownloadAsyncController(VideoData.VideoLocation, VideoData.VideoId, ActivityContext, ActivityName); if (!VideoControllers.CheckDownloadLinkIfExits()) { VideoControllers.StartDownloadManager(VideoData.Title, VideoData, ActivityName); } } } else if (DownloadIcon.Tag.ToString() == "Downloaded") { try { AlertDialog.Builder builder = new AlertDialog.Builder(ActivityContext); builder.SetTitle(ActivityContext.GetText(Resource.String.Lbl_Delete_video)); builder.SetMessage(ActivityContext.GetText(Resource.String.Lbl_Do_You_want_to_remove_video)); builder.SetPositiveButton(ActivityContext.GetText(Resource.String.Lbl_Yes), delegate { try { VideoDownloadAsyncController.RemoveDiskVideoFile(VideoData.VideoId + ".mp4"); DownloadIcon.SetImageResource(Resource.Drawable.ic_action_download); DownloadIcon.Tag = "false"; } catch (Exception exception) { Console.WriteLine(exception); } }); builder.SetNegativeButton(ActivityContext.GetText(Resource.String.Lbl_No), delegate { }); var alert = builder.Create(); alert.Show(); } catch (Exception exception) { Console.WriteLine(exception); } } else { DownloadIcon.SetImageResource(Resource.Drawable.ic_action_download); DownloadIcon.Tag = "false"; VideoControllers.StopDownloadManager(); } } catch (Exception exception) { Console.WriteLine(exception); } }