Esempio n. 1
0
 /// Play a track from FilePicker
 public static async Task PlayTrackFromFilePicker(TrackItem trackItem)
 {
     if (trackItem == null) return;
     await Locator.MediaPlaybackViewModel.TrackCollection.ResetCollection();
     await Locator.MediaPlaybackViewModel.TrackCollection.Add(trackItem, true);
     await Locator.MediaPlaybackViewModel.TrackCollection.SetCurrentTrackPosition(0);
     await Task.Run(async () => await Locator.MediaPlaybackViewModel.SetMedia(Locator.MusicPlayerVM.CurrentTrack, false));
 }
Esempio n. 2
0
 /// <summary>
 /// Adds a track to the Playlist
 /// </summary>
 /// <param name="album"></param>
 /// <param name="resetQueue"></param>
 /// <returns></returns>
 public static async Task AddTrackToPlaylist(TrackItem trackItem = null, bool resetQueue = true, bool play = true)
 {
     if (trackItem == null) return;
     if (resetQueue)
     {
         await Locator.MediaPlaybackViewModel.TrackCollection.ResetCollection();
     }
     await Locator.MediaPlaybackViewModel.TrackCollection.Add(trackItem, true);
     if (play)
         await PlayMusicTrack(trackItem.Id);
 }
Esempio n. 3
0
 /// <summary>
 /// Adds an album to the Playlist
 /// </summary>
 /// <param name="album"></param>
 /// <param name="resetQueue">Reset or not the current Playlist before adding new elements</param>
 /// <returns></returns>
 public static async Task AddAlbumToPlaylist(int albumId, bool resetQueue = true, bool play = true, TrackItem track = null, int index = 0)
 {
     if (resetQueue)
     {
         await Locator.MediaPlaybackViewModel.TrackCollection.ResetCollection();
     }
     var trackItems = Locator.MusicLibraryVM._trackDatabase.LoadTracksByAlbumId(albumId);
     await Locator.MediaPlaybackViewModel.TrackCollection.Add(trackItems);
     if (play)
     {
         if (track != null)
         {
             index = trackItems.IndexOf(trackItems.FirstOrDefault(x => x.Id == track.Id));
         }
         if (index != -1 && index < trackItems.Count)
             await PlayMusicTrack(trackItems[index].Id);
     }
 }
Esempio n. 4
0
 public Task Remove(TrackItem track)
 {
     var connection = new SQLiteAsyncConnection(DbPath);
     return connection.DeleteAsync(track);
 }
Esempio n. 5
0
 public async Task Add(TrackItem track)
 {
     var connection = new SQLiteAsyncConnection(DbPath);
     var query = connection.Table<TrackItem>().Where(x => x.Path == track.Path);
     var result = await query.ToListAsync();
     if (result.Count == 0)
         await connection.InsertAsync(track);
 }
Esempio n. 6
0
 public Task Update(TrackItem track)
 {
     var connection = new SQLiteAsyncConnection(DbPath);
     return connection.UpdateAsync(track);
 }
Esempio n. 7
0
 public static BackgroundTrackItem CreateBackgroundTrackItem(TrackItem track)
 {
     if (track == null) return null;
     BackgroundTrackItem audiotrack = new BackgroundTrackItem(track.Id, track.AlbumId, track.ArtistId, track.ArtistName, track.AlbumName, track.Name, track.Path);
     return audiotrack;
 }
Esempio n. 8
0
        public async static Task<TrackItem> GetTrackItemFromFile(StorageFile track)
        {
            //TODO: Warning, is it safe to consider this a good idea?
            var trackItem = await Locator.MusicLibraryVM._trackDatabase.LoadTrackByPath(track.Path);
            if (trackItem != null)
            {
                return trackItem;
            }

            MusicProperties trackInfos = null;
            try
            {
                trackInfos = await track.Properties.GetMusicPropertiesAsync();
            }
            catch
            {

            }
            trackItem = new TrackItem
            {
                ArtistName = (string.IsNullOrEmpty(trackInfos?.Artist)) ? Strings.UnknownArtist : trackInfos?.Artist,
                AlbumName = trackInfos?.Album ?? Strings.UnknownAlbum,
                Name = (string.IsNullOrEmpty(trackInfos?.Title)) ? track.DisplayName : trackInfos?.Title,
                Path = track.Path,
                Duration = trackInfos?.Duration ?? TimeSpan.Zero,
                File = track
            };
            return trackItem;
        }
Esempio n. 9
0
        public static async Task RemoveTrackFromCollectionAndDatabase(TrackItem trackItem)
        {
            await App.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                try
                {
                    Locator.MusicLibraryVM._trackDatabase.Remove(Locator.MusicLibraryVM.Tracks.FirstOrDefault(x => x.Path == trackItem.Path));
                    Locator.MusicLibraryVM.Tracks.Remove(Locator.MusicLibraryVM.Tracks.FirstOrDefault(x => x.Path == trackItem.Path));
                    var album = Locator.MusicLibraryVM.Albums.FirstOrDefault(x => x.Id == trackItem.AlbumId);
                    album?.Tracks.Remove(album.Tracks.FirstOrDefault(x => x.Path == trackItem.Path));

                    var artist = Locator.MusicLibraryVM.Artists.FirstOrDefault(x => x.Id == trackItem.ArtistId);
                    var artistalbum = artist?.Albums.FirstOrDefault(x => x.Id == trackItem.AlbumId);
                    artistalbum?.Tracks.Remove(artistalbum.Tracks.FirstOrDefault(x => x.Path == trackItem.Path));
                    if (album.Tracks.Count == 0)
                    {
                        // We should remove the album as a whole
                        Locator.MusicLibraryVM.Albums.Remove(album);
                        Locator.MusicLibraryVM._albumDatabase.Remove(album);
                        artist.Albums.Remove(artistalbum);
                    }
                    var playingTrack = Locator.MediaPlaybackViewModel.TrackCollection.Playlist.FirstOrDefault(x => x.Id == trackItem.Id);
                    if (playingTrack != null) Locator.MediaPlaybackViewModel.TrackCollection.Playlist.Remove(playingTrack);
                }
                catch
                {
                }
            });
        }
Esempio n. 10
0
 public static async Task AddToPlaylist(TrackItem trackItem, bool displayToastNotif = true)
 {
     if (Locator.MusicLibraryVM.CurrentTrackCollection == null) return;
     if (Locator.MusicLibraryVM.CurrentTrackCollection.Playlist.Contains(trackItem))
     {
         ToastHelper.Basic(Strings.TrackAlreadyExistsInPlaylist);
         return;
     }
     Locator.MusicLibraryVM.CurrentTrackCollection.Playlist.Add(trackItem);
     await Locator.MusicLibraryVM.TracklistItemRepository.Add(new TracklistItem()
     {
         TrackId = trackItem.Id,
         TrackCollectionId = Locator.MusicLibraryVM.CurrentTrackCollection.Id,
     });
     if (displayToastNotif)
         ToastHelper.Basic(string.Format(Strings.TrackAddedToYourPlaylist, trackItem.Name));
 }
Esempio n. 11
0
 public static Task DeletePlaylistTrack(TrackItem track, TrackCollection trackCollection)
 {
     return Locator.MusicLibraryVM.TracklistItemRepository.Remove(track.Id, trackCollection.Id);
 }
Esempio n. 12
0
 public static void AddTrack(TrackItem track)
 {
     Locator.MusicLibraryVM.Tracks.Add(track);
 }
Esempio n. 13
0
        private static async Task CreateDatabaseFromMusicFile(StorageFile item)
        {
            try
            {
                if (!VLCFileExtensions.AudioExtensions.Contains(item.FileType.ToLower())) return;
                var media = Locator.VLCService.GetMediaFromPath(item.Path);
                MediaProperties mP = Locator.VLCService.GetMusicProperties(media);
                if(mP == null)
                {
                    var props = await item.Properties.GetMusicPropertiesAsync();
                    mP = new MediaProperties()
                    {
                        Album = props.Album,
                        AlbumArtist = props.AlbumArtist,
                        Artist = props.Artist,
                        Title = props.Title,
                        Tracknumber = props.TrackNumber,
                        Genre = (props.Genre != null && props.Genre.Any()) ? props.Genre[0] : null,
                    };
                }
                if (mP != null)
                {
                    var artistName = mP.Artist;
                    var albumArtistName = mP.AlbumArtist;
                    ArtistItem artist = Locator.MusicLibraryVM._artistDatabase.LoadViaArtistName(string.IsNullOrEmpty(albumArtistName) ? artistName : albumArtistName);
                    if (artist == null)
                    {
                        artist = new ArtistItem();
                        artist.Name = string.IsNullOrEmpty(albumArtistName) ? artistName : albumArtistName;
                        await Locator.MusicLibraryVM._artistDatabase.Add(artist);
                        await App.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                        {
                            AddArtist(artist);
                        });
                    }

                    var albumName = mP.Album;
                    var albumYear = mP.Year;
                    AlbumItem album = await Locator.MusicLibraryVM._albumDatabase.LoadAlbumViaName(artist.Id, albumName);
                    if (album == null)
                    {
                        var albumUrl = Locator.VLCService.GetAlbumUrl(media);
                        var hasVLCFoundCover = false;
                        if (!string.IsNullOrEmpty(albumUrl) && albumUrl.StartsWith("file://"))
                        {
                            // The Uri will be like
                            // ms-appdata:///local/vlc/art/artistalbum/30 Seconds To Mars/B-sides & Rarities/art.jpg
                            hasVLCFoundCover = true;
                        }

                        album = new AlbumItem
                        {
                            Name = string.IsNullOrEmpty(albumName) ? string.Empty : albumName,
                            AlbumArtist = albumArtistName,
                            Artist = string.IsNullOrEmpty(albumArtistName) ? artistName : albumArtistName,
                            ArtistId = artist.Id,
                            Favorite = false,
                            Year = albumYear,
                            IsPictureLoaded = hasVLCFoundCover,
                            IsVLCCover = hasVLCFoundCover,
                        };
                        await Locator.MusicLibraryVM._albumDatabase.Add(album);
                        await App.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                        {
                            var artistFromCollection = Locator.MusicLibraryVM.Artists.FirstOrDefault(x => x.Id == album.ArtistId);
                            AddAlbum(album, artistFromCollection);
                            Locator.MainVM.InformationText = string.Format(Strings.AlbumsFound, Locator.MusicLibraryVM.Albums.Count);
                        });
                    }

                    TrackItem track = new TrackItem
                    {
                        AlbumId = album.Id,
                        AlbumName = album.Name,
                        ArtistId = artist.Id,
                        ArtistName = artistName,
                        CurrentPosition = 0,
                        Duration = mP.Duration,
                        Favorite = false,
                        Name = string.IsNullOrEmpty(mP.Title) ? item.DisplayName : mP.Title,
                        Path = item.Path,
                        Index = mP.Tracknumber,
                        DiscNumber = mP.DiscNumber,
                    };
                    await Locator.MusicLibraryVM._trackDatabase.Add(track);
                    await App.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => AddTrack(track));
                }
            }
            catch (Exception e)
            {
                ExceptionHelper.CreateMemorizedException("MusicLibraryManagement.CreateDatabaseFromMusicFile", e);
            }
        }
Esempio n. 14
0
 public async Task Add(TrackItem trackItem, bool isPlayingPlaylist)
 {
     if (Playlist.FirstOrDefault(x => x.Id == trackItem.Id) != null) return;
     trackItem.Index = (uint)Playlist.Count;
     Playlist.Add(trackItem);
     var backgroundTrack = BackgroundTaskTools.CreateBackgroundTrackItem(trackItem);
     await App.BackgroundAudioHelper.AddToPlaylist(backgroundTrack);
 }