public async void onappload()
        {

            try
            {
                ProgressRing();




                //var path = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "base.db3");
                //using (SQLiteConnection db = new SQLiteConnection(path))
                //{
                //    db.BeginTransaction();
                //List<StorageFile> filedata = new List<StorageFile>();
                //var d = from x in db.Table<playlistbase>() select x;
                //foreach (var sd in d)
                //{
                //    StorageFile str = await
                //                      Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.GetFileAsync(
                //                          sd.playlistdata);
                //    filedata.Add(str);
                //}


                //file = filedata;
                file = await JDeSerialize();
                Collections.Clear();
                if (file != null)
                {

                    //var c = from x in file orderby x.Name select x;
                    int co = 0;
                    foreach (var files in file)
                    {
                       // albumart(files);

                        String duration = null;
                        String album = "Unknown";

                        int count = 0;
                        List<string> formats = new List<string>
                                {
                                    ".mp3",
                                    ".aac",
                                    ".adt",
                                    ".adts",
                                    ".wav",
                                    ".ac3",
                                    ".ec3"
                                };
                        var ff = from x in formats where x.Equals(files.FileType.ToLower()) select x;
                        foreach (var s in ff)
                        {
                            count = count + 1;
                        }
                        if (count >= 1)
                        {
                            var Properties = await files.Properties.GetMusicPropertiesAsync();
                            duration = Properties.Duration.ToString(@"hh\:mm\:ss");
                            album = Properties.Album == "" ? "Unknown Album" : Properties.Album;

                        }
                        else
                        {
                            var proper = await files.Properties.GetVideoPropertiesAsync();
                            duration = proper.Duration.ToString(@"hh\:mm\:ss");
                        }
                        playlist playingking = new playlist
                            {
                                _displayname = files.DisplayName,
                                _contenttype = files.ContentType,
                                _mediafile = files,
                                _datacreated = duration,
                                _album = album,
                                _thumburi = new Uri("ms-appdata:///roaming/" + files.DisplayName + ".png"),
                            };

                        Collections.Add(playingking);
                        co = co + 1;
                        block1.Text = co.ToString();

                    }
                    Task.Run(async () =>
                    {

                        foreach (var files in file)
                        {
                            albumart(files);
                        }
                       
                    });
                    ItemSource();
                    //db.Dispose();
                    //db.Close();
                    try
                    {
                        var local = ApplicationData.Current.LocalSettings;
                        object mediastatefile = local.Values["mediastatefile"];
                        object mediastatetime = local.Values["mediastatetime"];
                        lastposition = Convert.ToDouble(mediastatetime);
                        futurelocation = mediastatefile.ToString();
                        StorageFile filedd = await StorageApplicationPermissions.FutureAccessList.GetFileAsync(mediastatefile.ToString());
                        if (filedd != null)
                        {
                            textBlock.Visibility = Visibility.Collapsed;
                            extensions = filedd.FileType.ToLower();
                            mediaElement.AutoPlay = false;
                            mediaElement.SetSource((await filedd.OpenAsync(FileAccessMode.Read)), "");
                        }
                        //Double minutes = Convert.ToDouble(mediastatetime.ToString())/60;
                        //Double seconds = Convert.ToDouble(mediastatetime.ToString())%60;
                        //TimelineMarker tlm=new TimelineMarker();
                        //  tlm.Time=new TimeSpan(0,0,0,30);
                        //  mediaElement.Markers.Add(tlm);
                        timer3.Interval = new TimeSpan(0, 0, 0, 1);
                        timer3.Start();
                        timer3.Tick += timer3_Tick;
                        // mediaElement.Position = TimeSpan.FromSeconds(lastposition);
                    }
                    catch
                    {
                    }

                    HideProgressGrid();
                }

                //}
            }
            catch
            {
                HideProgressGrid();
                //  ErrorCorrecting("023");
                // Debug.WriteLine("Error ->\n"+ex.Message);
                // new MessageDialog(ex.Message).ShowAsync();
            }
        }
        private async Task pickingfiles()
        {

            //await Dispatcher.RunAsync(CoreDispatcherPriority.High, async () =>
            //    {
            ProgressRing();
            textBlock.Visibility = Visibility.Collapsed;
            Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Clear();


            Collections.Clear();
            jList.Clear();
            //createtable();
            //var paths = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "base.db3");
            //using (SQLiteConnection db = new SQLiteConnection(paths))
            //{
            //db.BeginTransaction();

            //   ls1.Items.Add(files.DisplayName);
            //  new MessageDialog(  Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.MaximumItemsAllowed.ToString()).ShowAsync();
            //new MessageDialog(
            //   Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Entries.Count.ToString()).ShowAsync();

            int co = 0;
            var formats = new List<string>
                            {
                                ".mp3",
                                ".aac",
                                ".adt",
                                ".adts",
                                ".wav",
                                ".ac3",
                                ".ec3"
                            };

            foreach (StorageFile files in file)
            {
                if (co < 1000)
                {
                    //db.Insert(new playlistbase
                    //    {
                    //        playlistdata =
                    //            Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList
                    //                   .Add(
                    //                       files),
                    //    });

                    String duration = null;
                    String album = "Unknown";
                    StorageFile files1 = files;
                    var ff = from x in formats where x.Equals(files1.FileType.ToLower()) select x;
                    int count = ff.Count();
                    if (count >= 1)
                    {
                        var properties = await files.Properties.GetMusicPropertiesAsync();
                        duration = properties.Duration.ToString(@"hh\:mm\:ss");
                        album = properties.Album == "" ? "Unknown Album" : properties.Album;
                    }
                    else
                    {
                        var proper = await files.Properties.GetVideoPropertiesAsync();
                        duration = proper.Duration.ToString(@"hh\:mm\:ss");
                    }
                    var playingking = new playlist
                        {
                            _displayname = files.DisplayName,
                            _contenttype = files.ContentType,
                            _datacreated = duration,
                            _mediafile = files,
                            _album = album,
                            _thumburi = new Uri("ms-appdata:///roaming/" + files.DisplayName + ".png"),
                        };

                    Collections.Add(playingking);
                }
                else
                {
                    break;
                }
                //    co = Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Entries.Count();
                co = co + 1;
                block1.Text = co.ToString();
            }
            //  playlist.Files.Add(files);
            //db.Commit();
            //db.Dispose();
            //ls1.ItemsSource = p;
            ItemSource();
            Task.Run(async () =>
            {

                foreach (var files in file)
                {
                    jList.Add(new JsonClass
                    {
                        Futurelist =
                            Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(files),
                    });
                    albumart(files);
                }
                await JSerialize(jList);
            });


            HideProgressGrid();
            //ls1.DataContext = new filename(files.DisplayName);
            //ls1.Items.Add(new filename(files.DisplayName.ToString())); ;
            // mediaElement.SetSource((await files.OpenAsync(FileAccessMode.Read)),"");
            //}

            #region playlist

            //  await playlist.SaveAsAsync(KnownFolders.MusicLibrary, "rocks", NameCollisionOption.ReplaceExisting,PlaylistFormat.WindowsMedia);

            #endregion

            ls1.SelectedIndex = 0;
            ////});

        }
        private async void button1_Click(object sender, RoutedEventArgs e)
        {




            ApplicationViewState myViewState = ApplicationView.Value;

            if (myViewState == ApplicationViewState.Snapped)
            {
                Windows.UI.ViewManagement.ApplicationView.TryUnsnap();
            }

            FileOpenPicker openPicker = new FileOpenPicker();

            openPicker.SuggestedStartLocation = PickerLocationId.ComputerFolder;

            openPicker.FileTypeFilter.Add(".3g2");
            openPicker.FileTypeFilter.Add(".3gp2");
            openPicker.FileTypeFilter.Add(".3gp");
            openPicker.FileTypeFilter.Add(".3gpp");
            openPicker.FileTypeFilter.Add(".m4a");
            openPicker.FileTypeFilter.Add(".m4v");
            openPicker.FileTypeFilter.Add(".mp4v");
            openPicker.FileTypeFilter.Add(".mp4");
            openPicker.FileTypeFilter.Add(".mov");
            openPicker.FileTypeFilter.Add(".m2ts");
            openPicker.FileTypeFilter.Add(".asf");
            openPicker.FileTypeFilter.Add(".wm");
            openPicker.FileTypeFilter.Add(".vob");
            openPicker.FileTypeFilter.Add(".wmv");
            openPicker.FileTypeFilter.Add(".wma");
            openPicker.FileTypeFilter.Add(".aac");
            openPicker.FileTypeFilter.Add(".adt");
            openPicker.FileTypeFilter.Add(".mp3");
            openPicker.FileTypeFilter.Add(".wav");
            openPicker.FileTypeFilter.Add(".avi");
            openPicker.FileTypeFilter.Add(".ac3");
            openPicker.FileTypeFilter.Add(".ec3");



            openPicker.ViewMode = PickerViewMode.List;

            mediaElement.Pause();

            file1 = await openPicker.PickMultipleFilesAsync();
            // ls1.Visibility = Visibility.Visible;



            if (file1.Count > 0)
            {
                ProgressRing();


                Storyboard1.Stop();
                textBlock.Visibility = Visibility.Collapsed;
                // ls1.Items.Clear();
                Collections.Clear();
                jList.Clear();
                file = file1;
                a = 0;

                //  IStorageItem dc = file[0];

                //  var list = Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.Add(dc);
                //StorageFile f=await  Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.GetFileAsync(list);


                Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Clear();


                int co = 0;
                List<string> formats = new List<string> { ".mp3", ".aac", ".adt", ".adts", ".wav", ".ac3", ".ec3" };
                // StringBuilder output = new StringBuilder("Picked files:\n");
                // Application now has read/write access to the picked file(s)
                try
                {
                    //createtable();
                    //var paths = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "base.db3");
                    //using (SQLiteConnection db = new SQLiteConnection(paths))
                    //{
                    //    db.BeginTransaction();
                    foreach (StorageFile files in file)
                    {
                        //   ls1.Items.Add(files.DisplayName);
                        if (co < 999)
                        {
                            //db.Insert(new playlistbase
                            //    {
                            //        playlistdata =
                            //            Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(
                            //                files),
                            //    });

                            jList.Add(new JsonClass
                            {
                                Futurelist = Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(files),
                            });

                            albumart(files);

                            String duration = null;
                            String album = "Unknown";

                            StorageFile files1 = files;
                            var ff = from x in formats where x.Equals(files1.FileType.ToLower()) select x;
                            int count = ff.Count();
                            if (count >= 1)
                            {
                                var properties = await files.Properties.GetMusicPropertiesAsync();
                                duration = properties.Duration.ToString(@"hh\:mm\:ss");
                                album = properties.Album == "" ? "Unknown Album" : properties.Album;
                            }
                            else
                            {
                                var proper = await files.Properties.GetVideoPropertiesAsync();
                                duration = proper.Duration.ToString(@"hh\:mm\:ss");
                            }
                            var playingking = new playlist
                                {
                                    _displayname = files.DisplayName,
                                    _contenttype = files.ContentType,
                                    _thumburi = new Uri("ms-appdata:///roaming/" + files.DisplayName + ".png"),
                                    _datacreated = duration,
                                    _mediafile = files,
                                    _album = album,
                                };

                            Collections.Add(playingking);
                        }
                        else
                        {

                            break;
                        }

                        co = Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Entries.Count();
                        block1.Text = co.ToString();

                    }
                    ////  playlist.Files.Add(files);
                    //db.Commit();
                    //db.Dispose();

                    //ls1.ItemsSource = p;

                    await JSerialize(jList);
                    ItemSource();

                    //ls1.DataContext = new filename(files.DisplayName);
                    //ls1.Items.Add(new filename(files.DisplayName.ToString())); ;
                    // mediaElement.SetSource((await files.OpenAsync(FileAccessMode.Read)),"");
                    //}


                    #region playlist
                    //  await playlist.SaveAsAsync(KnownFolders.MusicLibrary, "rocks", NameCollisionOption.ReplaceExisting,PlaylistFormat.WindowsMedia);
                    #endregion
                    ls1.SelectedIndex = 0;
                    HideProgressGrid();
                }
                catch
                {

                    ErrorCorrecting("012");
                }

            }
            else
            {
                mediaElement.Play();
                ls1.Visibility = Visibility.Collapsed;

            }
        }