[UnitOfWork] public async Task<List<MusicInfo>> GetQueueEntry() { var queueEntrys = await queueRepository.GetAll().ToListAsync(); if (_musicInfos == null || _musicInfos.Count == 0) { var isSucc = await GetMusicInfos(); if (!isSucc.IsSucess) { //CommonHelper.ShowNoAuthorized(); } _musicInfos = isSucc.Result;
} var result = from queue in queueEntrys join musicInfo in _musicInfos on queue.MusicInfoId equals musicInfo.Id orderby queue.Rank select musicInfo; return result.ToList(); }
int artistColumn = mediaCursor.GetColumnIndex(MediaStore.Audio.Media.InterfaceConsts.Artist); int albumColumn = mediaCursor.GetColumnIndex(MediaStore.Audio.Media.InterfaceConsts.Album); int titleColumn = mediaCursor.GetColumnIndex(MediaStore.Audio.Media.InterfaceConsts.Title); int durationColumn = mediaCursor.GetColumnIndex(MediaStore.Audio.Media.InterfaceConsts.Duration); int uriColumn = mediaCursor.GetColumnIndex(MediaStore.Audio.Media.InterfaceConsts.Data); int idColumn = mediaCursor.GetColumnIndex(MediaStore.Audio.Media.InterfaceConsts.Id); int isMusicColumn = mediaCursor.GetColumnIndex(MediaStore.Audio.Media.InterfaceConsts.IsMusic); int albumIdColumn = mediaCursor.GetColumnIndex(MediaStore.Audio.Media.InterfaceConsts.AlbumId);
int isMusic; ulong duration, id; string artist, album, title, uri, genre, artwork, artworkId;
if (mediaCursor.MoveToFirst()) { do { isMusic = int.Parse(mediaCursor.GetString(isMusicColumn)); if (isMusic != 0) { ulong.TryParse(mediaCursor.GetString(durationColumn),out duration); artist = mediaCursor.GetString(artistColumn); album = mediaCursor.GetString(albumColumn); title = mediaCursor.GetString(titleColumn); uri = mediaCursor.GetString(uriColumn); ulong.TryParse(mediaCursor.GetString(idColumn), out id); artworkId = mediaCursor.GetString(albumIdColumn);
if (DeviceInfo.Version.Major < 10) { albumCursor = Application.Context.ContentResolver.Query( MediaStore.Audio.Albums.ExternalContentUri, _albumProjections, $"{MediaStore.Audio.Albums.InterfaceConsts.Id}=?", new string[] { artworkId }, null); int artworkColumn = albumCursor.GetColumnIndex(MediaStore.Audio.Media.InterfaceConsts.AlbumArt); if (albumCursor.MoveToFirst()) { artwork = albumCursor.GetString(artworkColumn) ?? string.Empty; } else { artwork = String.Empty; }
albumCursor?.Close(); artworkImage = artwork;
} else { var extUrl = MediaStore.Audio.Albums.ExternalContentUri; var albumArtUri = ContentUris.WithAppendedId(extUrl, long.Parse(artworkId));
try { //var art = System.IO.Path.Combine (Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "albumart" + artworkId + ".jpg"); var art = System.IO.Path.Combine(Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDocuments).AbsolutePath, "albumart" + artworkId + ".jpg");
var bitmap = Application.Context.ContentResolver.LoadThumbnail(albumArtUri, new Android.Util.Size(1024, 1024), null); var h = bitmap.Height; var w = bitmap.Width; var bb = bitmap.ByteCount;
using (Stream ms = new FileStream(art, FileMode.Create)) { bitmap.Compress(Bitmap.CompressFormat.Png, 100, ms); bitmap.Recycle(); } artworkImage = art; } catch (Exception e) { System.Console.WriteLine(e.Message); } } songs.Add(new MusicInfo() { Id = (int)id, Title = title, Artist = artist, AlbumTitle = album, Genre = genre, Duration = duration / 1000, Url = uri, AlbumArt = artworkImage }); genreCursor?.Close(); } } while (mediaCursor.MoveToNext()); } mediaCursor?.Close();
public partial async Task<InfoResult<List<MusicInfo>>> GetMusicInfos() { List<MusicInfo> musicInfos;
var result = false; if (await MediaLibraryAuthorization()) { musicInfos = await Task.Run(() => { var Infos = (from item in MediaQuery.Items where item.MediaType == MPMediaType.Music select new MusicInfo() { Id = (int)item.PersistentID, Title = item.Title, Url = item.AssetURL.ToString(), Duration = Convert.ToUInt64(item.PlaybackDuration),
var localSongs = new List<MusicInfo>(); List<StorageFile> songfiles = new List<StorageFile>(); if (musicFolder == null) { musicFolder = KnownFolders.MusicLibrary; }
public partial async Task<InfoResult<List<MusicInfo>>> GetMusicInfos() { List<MusicInfo> musicInfos; var result = false; if (await MediaLibraryAuthorization()) { musicInfos = await SetMusicListAsync(); result = true; } else { musicInfos = new List<MusicInfo>(); result = false; } return new InfoResult<List<MusicInfo>>(result, musicInfos);
public partial async Task<InfoResult<List<AlbumInfo>>> GetAlbumInfos() { List<AlbumInfo> albumInfo; var result = false;
if (await MediaLibraryAuthorization()) { var isSucc = await GetMusicInfos(); if (!isSucc.IsSucess) { //CommonHelper.ShowNoAuthorized();
} albumInfo = await Task.Run(() => { var info = (from item in isSucc.Result group item by item.AlbumTitle into c select new AlbumInfo() { Title = c.Key, GroupHeader = GetGroupHeader(c.Key),
AlbumArt = c.FirstOrDefault().AlbumArt, Musics = new ObservableCollection<MusicInfo>(c.Select(d => new MusicInfo() { Id = d.Id, Title = d.Title, Duration = d.Duration, Url = d.Url, AlbumTitle = d.AlbumTitle, Artist = d.Artist, AlbumArt = d.AlbumArt, IsFavourite = GetIsMyFavouriteContains(d.Title).Result, IsInitFinished = true }))
}).ToList(); return info; });
result = true;
} else { albumInfo = new List<AlbumInfo>(); result = false; } return new InfoResult<List<AlbumInfo>>(result, albumInfo);
public partial async Task<InfoResult<List<ArtistInfo>>> GetArtistInfos() { List<ArtistInfo> artistInfo; var result = false; if (await MediaLibraryAuthorization()) { var isSucc = await GetMusicInfos(); if (!isSucc.IsSucess) { //CommonHelper.ShowNoAuthorized();
} artistInfo = await Task.Run(() => {
var info = (from item in isSucc.Result group item by item.Artist into c select new ArtistInfo() { Title = c.Key, GroupHeader = GetGroupHeader(c.Key), Musics = new ObservableCollection<MusicInfo>(c.Select(d => new MusicInfo() { Id = d.Id, Title = d.Title, Duration = d.Duration, Url = d.Url, AlbumTitle = d.AlbumTitle, Artist = d.Artist, AlbumArt = d.AlbumArt, IsFavourite = GetIsMyFavouriteContains(d.Title).Result, IsInitFinished = true
}))
}).ToList(); return info; }); result = true;
} else { artistInfo = new List<ArtistInfo>(); result = false; } return new InfoResult<List<ArtistInfo>>(result, artistInfo); }