Exemplo n.º 1
0
        public MainWindow()
        {
            InitializeComponent();

            NotificationUtils.Initialize();

            var pl       = PlaylistsHelper.FromPath(@"https://smarttvnews.ru/apps/iptvchannels.m3u", (p) => NotificationUtils.ShowNotification(p, NotificationUtils.InfoType.Loading), CancellationToken.None);
            var channels = (pl as Playlist).Expand();

            vlc.Initialize(channels);
            vlc.Start();
            KeyDown += MainWindow_KeyDown;
        }
Exemplo n.º 2
0
        private void NewPlaylist(string path)
        {
            _cancellationTS_LoadPlaylist?.Cancel();
            _cancellationTS_LoadPlaylist = new CancellationTokenSource();
            _cancellationTS_LoadPlaylist.Token.Register(() =>
                                                        NotificationUtils.ShowNotification("Загрузка плейлиста отменена...", NotificationUtils.InfoType.VlcLoading));

            NotificationUtils.ShowNotification("Загрузка нового плейлиста...", NotificationUtils.InfoType.VlcLoading);

            Task.Factory.StartNew(() =>
            {
                MediaPath[] newPlaylist = null;
                var data = PlaylistsHelper.FromPath(
                    path,
                    (p) => NotificationUtils.ShowNotification(p + " загрузка...", NotificationUtils.InfoType.VlcLoading),
                    _cancellationTS_LoadPlaylist.Token,
                    isPlaylist: true);
                if (data is Playlist pl)
                {
                    newPlaylist = pl.Expand();
                }
                else if (data != null)
                {
                    newPlaylist = new[] { data }
                }
                ;
                if (newPlaylist != null && !_cancellationTS_LoadPlaylist.IsCancellationRequested)
                {
                    LoadPlaylist(newPlaylist);
                    InitCommands();
                    DataManager.Save(PlaylistPath, newPlaylist);
                    DataManager.Save(PlaylistUriPath, path);
                    _currentPlaylist = path;
                    NotificationUtils.ShowNotification("Плейлист загружен", NotificationUtils.InfoType.ChannelOK);
                }
                else
                {
                    NotificationUtils.ShowNotification("Плейлист не загружен", NotificationUtils.InfoType.Error);
                }
                _cancellationTS_LoadPlaylist = null;
            });
        }
        public void TestWritingPlaylist()
        {
            var playlists = new ObservableCollection <Playlist>()
            {
                new Playlist()
                {
                    Name          = "p01",
                    IsAppPlaylist = false,
                    TrackList     = new ObservableCollection <Track>()
                    {
                        new Track()
                        {
                            Id          = 1,
                            Tua         = "Levitate",
                            AlbumId     = 1,
                            CaSiId      = 1,
                            TheLoaiId   = 1,
                            IsLove      = true,
                            MediaKind   = MediaKind.Song,
                            NgayThemVao = DateTime.Today,
                            Url         = @"C:\Windows\System32\123.mp3"
                        },
                        new Track()
                        {
                            Id          = 2,
                            Tua         = "Glory",
                            AlbumId     = 1,
                            CaSiId      = 1,
                            TheLoaiId   = 1,
                            IsLove      = true,
                            MediaKind   = MediaKind.Song,
                            NgayThemVao = DateTime.Today,
                            Url         = @"C:\Windows\System32\1234.mp3"
                        },
                        new Track()
                        {
                            Id          = 3,
                            Tua         = "Qing hua ci",
                            AlbumId     = 1,
                            CaSiId      = 1,
                            TheLoaiId   = 1,
                            IsLove      = true,
                            MediaKind   = MediaKind.Song,
                            NgayThemVao = DateTime.Today,
                            Url         = @"C:\Windows\System32\1235.mp3"
                        },
                    }
                },
                new Playlist()
                {
                    Name          = "p02",
                    IsAppPlaylist = false,
                    TrackList     = new ObservableCollection <Track>()
                    {
                        new Track()
                        {
                            Id          = 4,
                            Tua         = "Ke ai nu ren",
                            AlbumId     = 1,
                            CaSiId      = 1,
                            TheLoaiId   = 1,
                            IsLove      = true,
                            MediaKind   = MediaKind.Song,
                            NgayThemVao = DateTime.Today,
                            Url         = @"C:\Windows\System32\1231.mp3"
                        },
                        new Track()
                        {
                            Id          = 5,
                            Tua         = "Way beyond",
                            AlbumId     = 1,
                            CaSiId      = 1,
                            TheLoaiId   = 1,
                            IsLove      = true,
                            MediaKind   = MediaKind.Song,
                            NgayThemVao = DateTime.Today,
                            Url         = @"C:\Windows\System32\12342.mp3"
                        },
                        new Track()
                        {
                            Id          = 6,
                            Tua         = "I do",
                            AlbumId     = 1,
                            CaSiId      = 1,
                            TheLoaiId   = 1,
                            IsLove      = true,
                            MediaKind   = MediaKind.Song,
                            NgayThemVao = DateTime.Today,
                            Url         = @"C:\Windows\System32\12353.mp3"
                        },
                    }
                }
            };

            var result = PlaylistsHelper.SavePlaylist(playlists);

            Assert.IsTrue(result);
        }
        public void descargar(string path, string archivo, string titulo, string link)
        {
            WebClient cliente2 = new WebClient();

            cliente2.DownloadFileAsync(new Uri("https://i.ytimg.com/vi/" + link.Split('=')[1] + "/mqdefault.jpg"), Android.OS.Environment.ExternalStorageDirectory + "/.gr3cache/portraits/" + link.Split('=')[1]);
            //new
            if (titulo.Trim().Length > 45)
            {
                titulo = titulo.Remove(45);
            }
            tituloo = titulo;


            var manige = DownloadManager.FromContext(this);
            var requ   = new DownloadManager.Request(Android.Net.Uri.Parse(archivo));

            requ.SetDescription("Espere por favor");
            requ.SetNotificationVisibility(DownloadVisibility.VisibleNotifyCompleted);
            requ.SetTitle(tituloo);
            var destino = Android.Net.Uri.FromFile(new Java.IO.File(path));

            if (SettingsHelper.GetSetting("rutadescarga") == Android.OS.Environment.DirectoryDownloads)
            {
                requ.SetDestinationInExternalPublicDir(SettingsHelper.GetSetting("rutadescarga"), Path.GetFileName(path));
            }
            else
            {
                requ.SetDestinationUri(destino);
            }
            requ.AllowScanningByMediaScanner();

            requ.SetVisibleInDownloadsUi(true);



            manige.Enqueue(requ);

            if (Path.GetFileName(path).EndsWith(".mp3"))
            {
                ////////////////si es mp3
                string datosviejos = "";
                if (File.Exists(Android.OS.Environment.ExternalStorageDirectory + "/.gr3cache/" + "downloaded.gr3d"))
                {
                    datosviejos = File.ReadAllText(Android.OS.Environment.ExternalStorageDirectory + "/.gr3cache/" + "downloaded.gr3d");
                }
                else
                {
                    var asss = File.Create(Android.OS.Environment.ExternalStorageDirectory + "/.gr3cache/" + "downloaded.gr3d");
                    asss.Close();
                }
                if (!Directory.Exists(Android.OS.Environment.ExternalStorageDirectory + "/.gr3cache/portraits"))
                {
                    Directory.CreateDirectory(Android.OS.Environment.ExternalStorageDirectory + "/.gr3cache/portraits");
                }

                if (!datosviejos.Contains(link.Split('=')[1]))
                {
                    var aafff = File.CreateText(Android.OS.Environment.ExternalStorageDirectory + "/.gr3cache/" + "downloaded.gr3d");
                    aafff.Write(datosviejos + Path.GetFileNameWithoutExtension(path) + "²" + link + "²" + path + "¤");
                    aafff.Close();
                }
                else
                {
                    var datosparsed   = PlaylistsHelper.GetMedia(Constants.CachePath + "/downloaded.gr3d");
                    var videoid       = link.Split('=')[1];
                    int indexelemento = datosparsed.FindIndex(ax => ax.Link.Contains(videoid));
                    datosparsed[indexelemento].Path = path;
                    var aafff = File.CreateText(Android.OS.Environment.ExternalStorageDirectory + "/.gr3cache/" + "downloaded.gr3d");
                    aafff.Write(PlaylistsHelper.SerializeMedia(datosparsed));
                    aafff.Close();
                }
            }
            //////////////////////////////////////////////si es mp4
            else
            {
                string datosviejos = "";
                if (File.Exists(Android.OS.Environment.ExternalStorageDirectory + "/.gr3cache/" + "downloaded.gr3d2"))
                {
                    datosviejos = File.ReadAllText(Android.OS.Environment.ExternalStorageDirectory + "/.gr3cache/" + "downloaded.gr3d2");
                }
                else
                {
                    var asss = File.Create(Android.OS.Environment.ExternalStorageDirectory + "/.gr3cache/" + "downloaded.gr3d2");
                    asss.Close();
                }
                if (!Directory.Exists(Android.OS.Environment.ExternalStorageDirectory + "/.gr3cache/portraits"))
                {
                    Directory.CreateDirectory(Android.OS.Environment.ExternalStorageDirectory + "/.gr3cache/portraits");
                }

                if (!datosviejos.Contains(link.Split('=')[1]))
                {
                    var aafff = File.CreateText(Android.OS.Environment.ExternalStorageDirectory + "/.gr3cache/" + "downloaded.gr3d2");
                    aafff.Write(datosviejos + Path.GetFileNameWithoutExtension(path) + "²" + link + "²" + path + "¤");
                    aafff.Close();
                }
                else
                {
                    var datosparsed   = PlaylistsHelper.GetMedia(Constants.CachePath + "/downloaded.gr3d2");
                    var videoid       = link.Split('=')[1];
                    int indexelemento = datosparsed.FindIndex(ax => ax.Link.Contains(videoid));
                    datosparsed[indexelemento].Path = path;
                    var aafff = File.CreateText(Android.OS.Environment.ExternalStorageDirectory + "/.gr3cache/" + "downloaded.gr3d2");
                    aafff.Write(PlaylistsHelper.SerializeMedia(datosparsed));
                    aafff.Close();
                }
                MultiHelper.ExecuteGarbageCollection();
            }



            /*
             * Random brandom = new Random();
             * WebClient cliente2= new WebClient();
             * cliente2.DownloadFileAsync(new Uri("https://i.ytimg.com/vi/" + link.Split('=')[1] + "/mqdefault.jpg"), Android.OS.Environment.ExternalStorageDirectory + "/.gr3cache/portraits/" + link.Split('=')[1]);
             * int randum = brandom.Next(2000, 50000) + brandom.Next(2000, 50000);
             * random = randum;
             * try {
             *  NotificationManager notificationManager =
             *   GetSystemService(Context.NotificationService) as NotificationManager;
             *  if (titulo.Trim().Length > 30)
             *  {
             *      titulo = titulo.Remove(30);
             *  }
             *  tituloo = titulo;
             *  var builder = new Notification.Builder(ApplicationContext);
             *  builder.SetContentTitle("Descargando " + titulo + "...");
             *  builder.SetContentText("Espere por favor");
             *
             *  builder.SetSmallIcon(Resource.Drawable.downloadbutton);
             *
             *
             *
             *  WebClient cliente = new WebClient();
             *
             * byte[] losbits = null;
             *  cliente.DownloadProgressChanged += (aasd, asddd) =>
             *  {
             *
             *      builder.SetContentTitle("Descargando "+titulo+"...");
             *      builder.SetContentText("Espere por favor");
             *      builder.SetSmallIcon(Resource.Drawable.downloadbutton);
             *      builder.SetProgress(100, asddd.ProgressPercentage, false);
             *      notificationManager.Notify(randum, builder.Build());
             *
             *  };
             * cliente.DownloadDataCompleted += (aa, aaa) =>
             * {
             *
             *  //  Intent intentss = new Intent(this,typeof(actividadacciones));
             *  //  intentss.PutExtra("prro", path);
             *  try {
             *  var selectedUri = Android.Net.Uri.Parse( prefs.GetString("rutadescarga",null)+ "/");
             *
             *  Intent intentssdd = new Intent(this,typeof(actividadadinfooffline));
             *  intentssdd.PutExtra("nombre", Path.GetFileName(path));
             *  intentssdd.PutExtra("link", link);
             *  intentssdd.PutExtra("path", path);
             *
             *
             *
             *
             *
             *  PendingIntent intentosd = PendingIntent.GetActivity(this, brandom.Next(2000, 50000) + brandom.Next(2000, 50000), intentssdd, PendingIntentFlags.UpdateCurrent);
             *
             *
             *  builder.SetContentTitle("Descarga completada de: "+titulo);
             *  builder.SetContentText("Toque para abrir");
             *  builder.SetSmallIcon(Resource.Drawable.downloadbutton);
             *  builder.SetContentIntent(intentosd);
             *      builder.SetOngoing(false);
             *      notificationManager.Notify(randum, builder.Build());
             *
             *  losbits = aaa.Result;
             *  var a = File.Create(path);
             *  a.Write(losbits, 0, losbits.Length);
             *  a.Close();
             *  string datosviejos = "";
             *  link = link.Replace('²', ' ');
             *  link= link.Replace('¤', ' ');
             *  path =path.Replace('²', ' ');
             *  path=path.Replace('¤', ' ');
             *
             *
             *  if (Path.GetFileName(path).EndsWith(".mp3")) {
             *  ///////////////////////////si es mp3
             *
             *  if (File.Exists(Android.OS.Environment.ExternalStorageDirectory + "/.gr3cache/" + "downloaded.gr3d"))
             *  {
             *     datosviejos = File.ReadAllText(Android.OS.Environment.ExternalStorageDirectory + "/.gr3cache/" + "downloaded.gr3d");
             *  }
             *  if (!Directory.Exists(Android.OS.Environment.ExternalStorageDirectory + "/.gr3cache/portraits"))
             *  {
             *      Directory.CreateDirectory(Android.OS.Environment.ExternalStorageDirectory + "/.gr3cache/portraits");
             *  }
             *
             *  if(!datosviejos.Contains(Path.GetFileNameWithoutExtension(path) + "²" + link + "²" + path + "¤"))
             *  {
             *      var aafff = File.CreateText(Android.OS.Environment.ExternalStorageDirectory + "/.gr3cache/" + "downloaded.gr3d");
             *      aafff.Write(datosviejos + Path.GetFileNameWithoutExtension(path) + "²" + link + "²" + path + "¤");
             *      aafff.Close();
             *
             *  }
             *
             *
             *  }
             *  //////////////////////////////////////////////si es mp4
             *  else
             *  {
             *      if (File.Exists(Android.OS.Environment.ExternalStorageDirectory + "/.gr3cache/" + "downloaded.gr3d2"))
             *      {
             *          datosviejos = File.ReadAllText(Android.OS.Environment.ExternalStorageDirectory + "/.gr3cache/" + "downloaded.gr3d2");
             *      }
             *      if (!Directory.Exists(Android.OS.Environment.ExternalStorageDirectory + "/.gr3cache/portraits"))
             *      {
             *          Directory.CreateDirectory(Android.OS.Environment.ExternalStorageDirectory + "/.gr3cache/portraits");
             *      }
             *
             *      if (!datosviejos.Contains(Path.GetFileNameWithoutExtension(path) + "²" + link + "²" + path + "¤"))
             *      {
             *          var aafff = File.CreateText(Android.OS.Environment.ExternalStorageDirectory + "/.gr3cache/" + "downloaded.gr3d2");
             *          aafff.Write(datosviejos + Path.GetFileNameWithoutExtension(path) + "²" + link + "²" + path + "¤");
             *          aafff.Close();
             *
             *      }
             *          clasesettings.recogerbasura();
             *  }
             *      completada = true;
             *  }
             *  catch (Exception)
             *  {
             *      clasesettings.recogerbasura();
             *      Toast.MakeText(this, "ha ocurrido un error al descargar intente de nuevo", ToastLength.Long).Show();
             *     // StopForeground(false);
             *  }
             *
             * };
             *
             *  cliente.DownloadData(new Uri(archivo));
             * }
             * catch (Exception)
             * {
             *  NotificationManager notificationManager =
             *  GetSystemService(Context.NotificationService) as NotificationManager;
             *  var builder = new Notification.Builder(ApplicationContext);
             *  builder.SetContentTitle("ERROR AL DESCARGAR: " + titulo);
             *  builder.SetContentText("Intente de nuevo");
             *  builder.SetSmallIcon(Resource.Drawable.downloadbutton);
             *  builder.SetOngoing(false);
             *  notificationManager.Notify(randum, builder.Build());
             *  clasesettings.recogerbasura();
             *
             * }
             */
        }