Exemplo n.º 1
0
 private async Task PlayCurrentTrack()
 {
     var list = Playlist.Items.ToList();
     await Core.PlaybackControl.Instance.AddAndSetIndexAt(
         list.Select(item => MusicPlaybackItem.CreateFromMediaFile(item.ToMediaFile())),
         list.IndexOf(PlaylistItem));
 }
Exemplo n.º 2
0
 private async void PlayCurrent()
 {
     var list = FileList.ToList();
     await Core.PlaybackControl.Instance.AddAndSetIndexAt(
         list.Select(item => MusicPlaybackItem.CreateFromMediaFile(item)),
         list.IndexOf(File));
 }
 private async void OnMenuAddClicked(object sender, RoutedEventArgs e)
 {
     await Core.PlaybackControl.Instance.AddFile(
         from item
         in Playlist.Items
         select MusicPlaybackItem.CreateFromMediaFile(
             item.ToMediaFile()));
 }
Exemplo n.º 4
0
        private async void OnAllMusicItemTapped(object sender, TappedRoutedEventArgs e)
        {
            var item = (sender as FrameworkElement).DataContext as DbMediaFile;
            var idx  = AllFiles.IndexOf(item);

            var items = AllFiles.Select(c => MusicPlaybackItem.CreateFromMediaFile(c));
            await PlaybackControl.Instance.AddAndSetIndexAt(items, idx);
        }
Exemplo n.º 5
0
 private async void OnMenuAddClicked(object sender, RoutedEventArgs e)
 {
     var playlist = (sender as FrameworkElement).DataContext as Playlist;
     await PlaybackControl.Instance.AddFile(
         from item
         in playlist.Items
         select MusicPlaybackItem.CreateFromMediaFile(
             item.ToMediaFile()));
 }
        private async void OnPlayButtonClick(object sender, RoutedEventArgs e)
        {
            var files = ViewModel.ArtistAlbums
                        .SelectMany(x => x.MediaFiles)
                        .Select(x => MusicPlaybackItem.CreateFromMediaFile(x))
                        .ToArray();

            PlaybackControl.Instance.Clear();
            await PlaybackControl.Instance.AddFile(files, -1);
        }
Exemplo n.º 7
0
 public override async void Execute(object parameter)
 {
     if (parameter is int)
     {
         await PlaybackControl.Instance.AddFile((int)parameter);
     }
     else if (parameter is DbMediaFile)
     {
         await PlaybackControl.Instance.AddFile(
             MusicPlaybackItem.CreateFromMediaFile((DbMediaFile)parameter));
     }
 }
Exemplo n.º 8
0
        private async void OnShuffleAllClick(object sender, RoutedEventArgs e)
        {
            if (GlobalLibraryCache.CachedDbMediaFile == null)
            {
                await GlobalLibraryCache.LoadMediaAsync();
            }
            var s = from x in Shuffle(GlobalLibraryCache.CachedDbMediaFile, new Random())
                    select MusicPlaybackItem.CreateFromMediaFile(x);

            Core.PlaybackControl.Instance.Clear();
            await Core.PlaybackControl.Instance.AddAndSetIndexAt(s, 0);
        }
Exemplo n.º 9
0
        public static async Task HandleM3uAsync(StorageFile file, List <MusicPlaybackItem> add)
        {
            try
            {
                using (var stream = await file.OpenStreamForReadAsync())
                    using (var sr = new StreamReader(stream))
                    {
                        var musicItems = M3u.Parse(sr.Lines());
                        foreach (var music in musicItems)
                        {
                            try
                            {
                                var f = await NativeMethods.GetStorageFileFromPathAsync(music);

                                if (f == null)
                                {
                                    continue;
                                }
                                IMediaInfo info = null;
                                using (var s = await f.OpenAsync(FileAccessMode.Read))
                                {
                                    NativeMethods.GetMediaInfoFromStream(s, out info);
                                }
                                if (info == null)
                                {
                                    continue;
                                }
                                var prop = await file.GetBasicPropertiesAsync();

                                var internalEntity = DbMediaFile.FromMediaInfo(info, prop.DateModified);
                                internalEntity.IsExternal = true;

                                internalEntity.Path = f.Path;
                                internalEntity.Id   = -65535;
                                if (string.IsNullOrWhiteSpace(internalEntity.Title) &&
                                    !string.IsNullOrWhiteSpace(internalEntity.Path))
                                {
                                    internalEntity.Title = Path.GetFileNameWithoutExtension(internalEntity.Path);
                                }
                                add.Add(MusicPlaybackItem.CreateFromMediaFile(internalEntity));
                            }
                            catch { }
                        }
                    }
            }
            catch { }
        }
        private async void PlayCurrent()
        {
            var list = FileList.ToList();
            var idx  = list.IndexOf(File);

            if (idx == -1)
            {
                return;
            }
            Core.PlaybackControl.Instance.Clear();
            await Core.PlaybackControl.Instance.AddFile(
                from item
                in list
                select MusicPlaybackItem.CreateFromMediaFile(item.File));

            Core.PlaybackControl.Instance.SetIndex(idx);
        }
Exemplo n.º 11
0
        public static async Task HandleWplAsync(StorageFile file, List <MusicPlaybackItem> addItem)
        {
            try
            {
                if (!ApiInformation.IsApiContractPresent("Windows.Media.Playlists.PlaylistsContract", 1))
                {
                    //TODO: Tell user the platform is not supported.
                    return;
                }
                var playlist = await Windows.Media.Playlists.Playlist.LoadAsync(file);

                foreach (var item in playlist.Files)
                {
                    IMediaInfo info = null;
                    using (var stream = await item.OpenAsync(FileAccessMode.Read))
                    {
                        NativeMethods.GetMediaInfoFromStream(stream, out info);
                    }
                    if (info == null)
                    {
                        continue;
                    }
                    var prop = await item.GetBasicPropertiesAsync();

                    var internalEntity = DbMediaFile.FromMediaInfo(info, prop.DateModified);
                    internalEntity.IsExternal = true;

                    internalEntity.Path = item.Path;
                    internalEntity.Id   = -65535;
                    if (string.IsNullOrWhiteSpace(internalEntity.Title) &&
                        !string.IsNullOrWhiteSpace(internalEntity.Path))
                    {
                        internalEntity.Title = Path.GetFileNameWithoutExtension(internalEntity.Path);
                    }
                    addItem.Add(MusicPlaybackItem.CreateFromMediaFile(internalEntity));
                }
            }
            catch { }
        }
Exemplo n.º 12
0
        public static async Task <IEnumerable <MusicPlaybackItem> > HandleFileWithCue(StorageFile file, CueFile cue)
        {
            //Cue files will only have track number
            var items = cue.Indices
                        .OrderBy(c => ParseWithDefaultFallback(
                                     c.TrackInfo.TrackNumber));
            List <MusicPlaybackItem> files = new List <MusicPlaybackItem>();
            IMediaInfo info = null;

            using (var stream = await file.OpenAsync(FileAccessMode.Read))
            {
                NativeMethods.GetMediaInfoFromStream(
                    stream,
                    out info);
            }
            if (info == null)
            {
                return(files);
            }
            var prop = await file.GetBasicPropertiesAsync();

            foreach (ManagedAudioIndexCue item in items)
            {
                if (item.TrackInfo.Duration == TimeSpan.Zero)
                {
                    (item.TrackInfo as CueMediaInfo).Duration
                          = item.Duration
                          = info.Duration - item.StartTime;
                }
                var internalEntity = DbMediaFile.FromMediaInfo(item.TrackInfo, prop.DateModified);
                internalEntity.IsExternal = true;
                internalEntity.StartTime  = (int)item.StartTime.TotalMilliseconds;
                internalEntity.Path       = file.Path;
                internalEntity.Id         = -65535;
                files.Add(MusicPlaybackItem.CreateFromMediaFile(internalEntity));
            }
            return(files);
        }
Exemplo n.º 13
0
        private async void OnPlayItemsListViewDrop(object sender, DragEventArgs e)
        {
            IEnumerable <MusicPlaybackItem> addItems = null;

            if (e.DataView.Contains(StandardDataFormats.StorageItems))
            {
                var items = await e.DataView.GetStorageItemsAsync();

                addItems = await FileOpen.GetPlaybackItemsFromFilesAsync(
                    await FileOpen.GetAllFiles(items));
            }
            else if (e.DataView.Contains(StandardDataFormats.Text))
            {
                var items = DragHelper.Get(await e.DataView.GetTextAsync());

                if (items is Playlist)
                {
                    var list = items as Playlist;
                    addItems =
                        from i
                        in list.Items
                        select MusicPlaybackItem.CreateFromMediaFile(i.ToMediaFile());
                }
                else if (items is PlaylistItem)
                {
                    addItems = new MusicPlaybackItem[]
                    {
                        MusicPlaybackItem.CreateFromMediaFile(
                            (items as PlaylistItem).ToMediaFile())
                    };
                }
                else if (items is IEnumerable <DbMediaFile> )
                {
                    addItems =
                        from i
                        in items as IEnumerable <DbMediaFile>
                        select MusicPlaybackItem.CreateFromMediaFile(i);
                }
                else if (items is DbMediaFile)
                {
                    addItems = new MusicPlaybackItem[]
                    {
                        MusicPlaybackItem.CreateFromMediaFile(items as DbMediaFile)
                    };
                }
            }
            if (addItems != null)
            {
                var targetListView = sender as ListView;

                if (targetListView == null)
                {
                    return;
                }
                targetListView.Background = null;
                Border border = VisualTreeHelper.GetChild(targetListView, 0) as Border;

                ScrollViewer scrollViewer      = border.Child as ScrollViewer;
                var          droppedPosition   = e.GetPosition(targetListView).Y + scrollViewer.VerticalOffset;
                var          itemsSource       = targetListView.ItemsSource as IList;
                var          highWaterMark     = 3d; // 3px of padding
                var          dropIndex         = 0;
                var          foundDropLocation = false;

                for (int i = 0; i < itemsSource.Count && !foundDropLocation; i++)
                {
                    var itemContainer = (ListViewItem)targetListView.ContainerFromIndex(i);

                    if (itemContainer != null)
                    {
                        highWaterMark = highWaterMark + itemContainer.ActualHeight;
                    }

                    if (droppedPosition <= highWaterMark)
                    {
                        dropIndex         = i;
                        foundDropLocation = true;
                    }
                }

                if (foundDropLocation)
                {
                    await Core.PlaybackControl.Instance.AddFile(addItems, dropIndex);
                }
                else
                {
                    await Core.PlaybackControl.Instance.AddFile(addItems);
                }
            }
        }
Exemplo n.º 14
0
        public static async Task <List <MusicPlaybackItem> > GetPlaybackItemsFromFilesAsync(IReadOnlyList <IStorageItem> items)
        {
            var files = new List <StorageFile>();
            var added = new List <MusicPlaybackItem>();

            // [| (cue file, full file path of missing file) |]
            var failedCue = new List <Tuple <StorageFile, string> >();

            foreach (var file in await GetAllFiles(items))
            {
                files.Add(file);
            }
            var listFiles = PickAndRemoveCueM3uWplFiles(files);

            foreach (var cueFile in listFiles.Item1)
            {
                try
                {
                    var failedFileName = await HandleCueFileOpen(cueFile, files, added);

                    if (failedFileName != null)
                    {
                        failedCue.Add(new Tuple <StorageFile, string>(cueFile, failedFileName));
                    }
                }
                catch { }
            }

            foreach (var m3uFile in listFiles.Item2)
            {
                await HandleM3uAsync(m3uFile, added);
            }

            foreach (var wplFile in listFiles.Item3)
            {
                await HandleWplAsync(wplFile, added);
            }

            foreach (var file in files)
            {
                try
                {
                    IMediaInfo info = null;
                    using (var stream = await file.OpenAsync(FileAccessMode.Read))
                    {
                        NativeMethods.GetMediaInfoFromStream(stream, out info);
                    }
                    if (info == null)
                    {
                        continue;
                    }
                    var cue = info.AllProperties["cuesheet"];
                    if (!string.IsNullOrWhiteSpace(cue))
                    {
                        var cueItems = await HandleFileWithCue(file,
                                                               CueFile.CreateFromString(cue));

                        added.AddRange(cueItems);
                        continue;
                    }
                    var prop = await file.GetBasicPropertiesAsync();

                    var internalEntity = DbMediaFile.FromMediaInfo(info, prop.DateModified);

                    internalEntity.IsExternal = true;

                    internalEntity.Path = file.Path;
                    internalEntity.Id   = -65535;

                    if (string.IsNullOrWhiteSpace(internalEntity.Title) &&
                        !string.IsNullOrWhiteSpace(internalEntity.Path))
                    {
                        internalEntity.Title = Path.GetFileNameWithoutExtension(internalEntity.Path);
                    }
                    added.Add(MusicPlaybackItem.CreateFromMediaFile(internalEntity));
                }
                catch { }
            }
            if (failedCue.Count > 0)
            {
                added.AddRange(
                    await FileOpenFailure.AddFailedFilePath(
                        failedCue));
            }
            return(added);
        }
Exemplo n.º 15
0
 private async void OnAddAsNextClicked(object sender, RoutedEventArgs e)
 {
     await Core.PlaybackControl.Instance.AddFile(
         MusicPlaybackItem.CreateFromMediaFile(File), -2);
 }
Exemplo n.º 16
0
 private async void OnAddButtonClick(object sender, RoutedEventArgs e)
 {
     await Core.PlaybackControl.Instance.AddFile(
         MusicPlaybackItem.CreateFromMediaFile(
             PlaylistItem.ToMediaFile()));
 }