public void GetFiles()
        {
            this.FileDetails = new List <FileDetail>();
            var files = _localFile.UpdatePlayListAsync();
            List <FileDetail> fileDetails = files;

            this.FileDetails = (from f in fileDetails
                                //where f.Type == this.FileType
                                orderby f.Parent, f.Path, f.Name
                                select f).ToList();
        }
Пример #2
0
        public async Task <List <MediaFile> > GetFilesAsync()
        {
            MediaFiles = new List <MediaFile>();
            var mediaFiles = new List <MediaFile>();

            if (await _devicePermissionServices.RequestReadStoragePermission())
            {
                var fileDetails = await _localFile.UpdatePlayListAsync();

                if (fileDetails == null || fileDetails.Count == 0 && !fileDetails.Any(f => f.Type.EndsWith(FileType)))
                {
                    SetActivityResource(true, false, false, true, string.Empty, string.Empty,
                                        TextResources.NoFileExists);
                }
                else
                {
                    foreach (var content in fileDetails.Where(f => f.Type.EndsWith(FileType)).OrderBy(f => f.Name))
                    {
                        mediaFiles.Add(new MediaFile()
                        {
                            Url  = content.Path,
                            Type = MediaFileType.Audio,
                            MetadataExtracted = false,
                            Availability      = ResourceAvailability.Local,
                        });
                    }
                }

                MediaFiles    = mediaFiles;
                IsMediaExists = MediaFiles.Count > 0;
                if (MediaFiles.Count == 0)
                {
                    SetActivityResource(true, false, false, true, string.Empty, string.Empty,
                                        TextResources.NoFileExists);
                }
            }
            else
            {
                ErrorMessage = TextResources.MessagePermissionReadStorageRequired;
                IsError      = true;
            }

            return(MediaFiles);
        }
Пример #3
0
        private List <MediaFile> GetFilesAsync()
        {
            var         mediaFiles  = new List <MediaFile>();
            StackLayout stackLayout = new StackLayout();
            var         fileDetails = _localFile.UpdatePlayListAsync();
            var         messages    = _localFile.Messages;

            if (fileDetails == null || fileDetails.Count == 0)
            {
                messages.Add("FileDetails Count: #" + fileDetails?.Count);
            }

            if (messages.Count > 0)
            {
                foreach (var message in messages)
                {
                    stackLayout.Children.Add(new Label()
                    {
                        FormattedText = new FormattedString()
                        {
                            Spans = { new Span()
                                      {
                                          Text = message
                                      } }
                        }
                    });
                }
            }

            //if (fileDetails == null || fileDetails.Count == 0)
            //{
            //var fileDetail = await _localFile.GetLogicalDrivesAsync();
            //messages = _localFile.Messages;
            //if (fileDetail == null || fileDetail.Count == 0)
            //{
            //    messages.Add("FileDetail Count: #" + fileDetail?.Count);
            //}

            //if (messages.Count > 0)
            //{
            //    foreach (var message in messages)
            //    {
            //        stackLayout.Children.Add(new Label()
            //        {
            //            FormattedText = new FormattedString() {Spans = {new Span() {Text = message}}}
            //        });
            //    }
            //}

            //}
            MessageContent = stackLayout;

            if (fileDetails == null ||
                fileDetails.Count == 0 ||
                !fileDetails.Any(f => f.Type.EndsWith(FileType)))
            {
                SetActivityResource(showError: true, errorMessage: TextResources.NoFileOrPermission);
            }
            else
            {
                foreach (var content in fileDetails.Where(f => f.Type.EndsWith(FileType)).OrderBy(f => f.Name))
                {
                    mediaFiles.Add(new MediaFile()
                    {
                        Url  = content.Path,
                        Type = MediaFileType.Audio,
                        MetadataExtracted = false,
                        Availability      = ResourceAvailability.Local,
                    });
                }

                //foreach (var content in fileDetail.Where(f => f.Type.EndsWith(FileType)).OrderBy(f => f.Name))
                //{
                //    mediaFiles.Add(new MediaFile()
                //    {
                //        Url = content.Path,
                //        Type = MediaFileType.Audio,
                //        MetadataExtracted = false,
                //        Availability = ResourceAvailability.Local,
                //    });
                //}

                MediaFiles = mediaFiles;
            }

            IsMediaExists = MediaFiles.Count > 0;
            return(MediaFiles);
        }