Exemplo n.º 1
0
        private static void LoadSystemPlayBar(int index)
        {
            if (index >= List.Count)
            {
                return;
            }

            HyPlayItem hpi = List[index];
            AudioInfo  ai  = hpi.AudioInfo;
            //然后设置播放相关属性
            MediaItemDisplayProperties properties = PlaybackList.Items[index].GetDisplayProperties();

            properties.Type = MediaPlaybackType.Music;
            properties.MusicProperties.AlbumTitle = ai.Album;
            properties.MusicProperties.Artist     = ai.Artist;
            properties.MusicProperties.Title      = ai.SongName;

            try
            {
                if (hpi.isOnline)
                {
                    properties.Thumbnail = RandomAccessStreamReference.CreateFromUri(new Uri(hpi.NcPlayItem.Album.cover + "?param=" + StaticSource.PICSIZE_AUDIO_PLAYER_COVER));
                }
                else
                {
                    properties.Thumbnail = ai.Thumbnail;
                }
            }
            catch { }

            hpi.MediaItem.ApplyDisplayProperties(properties);
        }
Exemplo n.º 2
0
        public static HyPlayItem AppendNCPlayItem(NCPlayItem ncp)
        {
            AudioInfo ai = new AudioInfo()
            {
                Album                = ncp.Album.name,
                ArtistArr            = ncp.Artist.Select((artist => artist.name)).ToArray(),
                Artist               = string.Join(" / ", ncp.Artist.Select((artist => artist.name))),
                LengthInMilliseconds = ncp.LengthInMilliseconds,
                Picture              = ncp.Album.cover,
                SongName             = ncp.songname,
                tag = ncp.tag
            };
            HyPlayItem hpi = new HyPlayItem()
            {
                AudioInfo  = ai,
                isOnline   = true,
                ItemType   = HyPlayItemType.Netease,
                Name       = ncp.songname,
                NcPlayItem = ncp,
                Path       = ncp.url
            };

            List.Add(hpi);
            return(hpi);
        }
Exemplo n.º 3
0
        public static async void AudioMediaPlaybackList_CurrentItemChanged(MediaPlaybackList sender, CurrentMediaPlaybackItemChangedEventArgs args)
        {
            if (args.NewItem == null)
            {
                RequestSyncPlayList();
                return;
            }

            NowPlaying = (int)HyPlayList.PlaybackList.CurrentItemIndex;
            if (!MPIToIndex.ContainsKey(args.NewItem))
            {
                return;
            }

            HyPlayItem hpi = List[MPIToIndex[args.NewItem]];
            AudioInfo  ai  = hpi.AudioInfo;

            //LoadSystemPlayBar(MPIToIndex[args.NewItem]);
            if (hpi.ItemType == HyPlayItemType.Netease && hpi.AudioInfo.Lyric == null)
            {
                PureLyricInfo lrcs = await LoadNCLyric(hpi);

                ai.Lyric   = lrcs.PureLyrics;
                ai.TrLyric = lrcs.TrLyrics;
            }
            //先进行歌词转换以免被搞
            Lyrics = Utils.ConvertPureLyric(ai.Lyric);
            Utils.ConvertTranslation(ai.TrLyric, Lyrics);
            hpi.AudioInfo = ai;
            //这里为调用订阅本事件的元素
            Invoke(() => OnPlayItemChange?.Invoke(hpi));
        }
Exemplo n.º 4
0
        public static async void AppendFile(StorageFile sf)
        {
            TagLib.File afi = TagLib.File.Create(new UwpStorageFileAbstraction(sf), ReadStyle.Average);
            AudioInfo   ai  = new AudioInfo()
            {
                Album  = string.IsNullOrEmpty(afi.Tag.Album) ? "未知专辑" : afi.Tag.Album,
                Artist = string.IsNullOrEmpty(string.Join('/', afi.Tag.Performers)) ? "未知歌手" : string.Join('/', afi.Tag.Performers),
                LengthInMilliseconds = afi.Properties.Duration.TotalMilliseconds,
                SongName             = string.IsNullOrEmpty(afi.Tag.Title) ? "Untitled" : afi.Tag.Title,
                LocalSongFile        = sf
            };

            //记载歌词
            try
            {
                StorageFile lrcfile = await(await sf.GetParentAsync()).GetFileAsync(Path.ChangeExtension(sf.Name, "lrc"));
                ai.Lyric = await FileIO.ReadTextAsync(lrcfile);
            }
            catch (Exception) { }
            try
            {
                BitmapImage img = new BitmapImage();
                using (InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream())
                {
                    stream.AsStreamForWrite().Write(afi.Tag.Pictures[0].Data.ToArray(), 0,
                                                    afi.Tag.Pictures[0].Data.ToArray().Length);
                    stream.Seek(0);
                    await img.SetSourceAsync(stream);

                    InMemoryRandomAccessStream streamb = new InMemoryRandomAccessStream();
                    streamb.AsStreamForWrite().Write(afi.Tag.Pictures[0].Data.ToArray(), 0,
                                                     afi.Tag.Pictures[0].Data.ToArray().Length);
                    streamb.Seek(0);
                    ai.Thumbnail = Windows.Storage.Streams.RandomAccessStreamReference.CreateFromStream(streamb);
                }

                ai.BitmapImage = img;
            }
            catch (Exception) { }

            HyPlayItem hyPlayItem = new HyPlayItem()
            {
                AudioInfo = ai,
                isOnline  = false,
                ItemType  = HyPlayItemType.Local,
                Name      = ai.SongName,
                Path      = sf.Path
            };

            List.Add(hyPlayItem);
            RequestSyncPlayList();
        }
Exemplo n.º 5
0
        public static async void LoadLyrics(HyPlayItem hpi)
        {
            if (hpi.ItemType == HyPlayItemType.Netease && hpi.AudioInfo.Lyric == null)
            {
                PureLyricInfo lrcs = await LoadNCLyric(hpi);

                hpi.AudioInfo.Lyric   = lrcs.PureLyrics;
                hpi.AudioInfo.TrLyric = lrcs.TrLyrics;
            }
            //先进行歌词转换以免被搞
            Lyrics = Utils.ConvertPureLyric(hpi.AudioInfo.Lyric);
            Utils.ConvertTranslation(hpi.AudioInfo.TrLyric, Lyrics);
            Invoke(() => OnLyricLoaded?.Invoke());
        }
Exemplo n.º 6
0
        public static async Task <bool> AppendFile(StorageFile sf)
        {
            //TagLib.File afi = TagLib.File.Create(new UwpStorageFileAbstraction(sf), ReadStyle.Average);
            var mdp = await sf.Properties.GetMusicPropertiesAsync();

            string[] contributingArtistsKey = { "System.Music.Artist" };
            IDictionary <string, object> contributingArtistsProperty =
                await mdp.RetrievePropertiesAsync(contributingArtistsKey);

            string[] contributingArtists = contributingArtistsProperty["System.Music.Artist"] as string[];
            if (contributingArtists is null)
            {
                contributingArtists = new[] { "未知歌手" };
            }
            AudioInfo ai = new AudioInfo()
            {
                tag                  = "本地",
                Album                = string.IsNullOrEmpty(mdp.Album) ? "未知专辑" : mdp.Album,
                ArtistArr            = contributingArtists,
                Artist               = string.IsNullOrEmpty(string.Join('/', contributingArtists)) ? "未知歌手" : string.Join('/', contributingArtists),
                LengthInMilliseconds = mdp.Duration.TotalMilliseconds,
                SongName             = string.IsNullOrEmpty(mdp.Title) ? sf.DisplayName : mdp.Title,
                LocalSongFile        = sf
            };

            //记载歌词
            try
            {
                StorageFile lrcfile = await(await sf.GetParentAsync()).GetFileAsync(Path.ChangeExtension(sf.Name, "lrc"));
                ai.Lyric = await FileIO.ReadTextAsync(lrcfile);
            }
            catch (Exception) { }

            HyPlayItem hyPlayItem = new HyPlayItem()
            {
                AudioInfo = ai,
                isOnline  = false,
                ItemType  = HyPlayItemType.Local,
                Name      = ai.SongName,
                Path      = sf.Path
            };

            List.Add(hyPlayItem);
            return(true);
        }
Exemplo n.º 7
0
        public static async Task <PureLyricInfo> LoadNCLyric(HyPlayItem ncp)
        {
            (bool isOk, Newtonsoft.Json.Linq.JObject json) = await Common.ncapi.RequestAsync(
                CloudMusicApiProviders.Lyric,
                new Dictionary <string, object>() { { "id", ncp.NcPlayItem.sid } });

            if (isOk)
            {
                if (json.ContainsKey("nolyric") && json["nolyric"].ToString().ToLower() == "true")
                {
                    return(new PureLyricInfo()
                    {
                        PureLyrics = "[00:00.000] 纯音乐 请欣赏",
                        TrLyrics = null
                    });
                }
                else if (json.ContainsKey("uncollected") && json["uncollected"].ToString().ToLower() == "true")
                {
                    return(new PureLyricInfo()
                    {
                        PureLyrics = "[00:00.000] 无歌词 请欣赏",
                        TrLyrics = null
                    });
                }
                else
                {
                    try
                    {
                        return(new PureLyricInfo()
                        {
                            PureLyrics = json["lrc"]["lyric"].ToString(),
                            TrLyrics = json["tlyric"]["lyric"].ToString()
                        });
                    }
                    catch (Exception)
                    {
                        //DEBUG
                    }
                }
            }

            return(new PureLyricInfo());
        }
Exemplo n.º 8
0
        public static async void LoadLyrics(HyPlayItem hpi)
        {
            if (hpi.ItemType == HyPlayItemType.Netease && hpi.AudioInfo.Lyric == null)
            {
                PureLyricInfo lrcs = await LoadNCLyric(hpi);

                hpi.AudioInfo.Lyric   = lrcs.PureLyrics;
                hpi.AudioInfo.TrLyric = lrcs.TrLyrics;
            }

            //先进行歌词转换以免被搞
            Lyrics = Utils.ConvertPureLyric(hpi.AudioInfo.Lyric);
            Utils.ConvertTranslation(hpi.AudioInfo.TrLyric, Lyrics);
            if (Lyrics.Count != 0 && Lyrics[0].LyricTime != TimeSpan.Zero)
            {
                Lyrics.Insert(0, new SongLyric()
                {
                    HaveTranslation = false, LyricTime = TimeSpan.Zero, PureLyric = ""
                });
            }
            lyricpos = 0;
            Common.Invoke(() => OnLyricLoaded?.Invoke());
        }
Exemplo n.º 9
0
        public static void AudioMediaPlaybackList_CurrentItemChanged(MediaPlaybackList sender, CurrentMediaPlaybackItemChangedEventArgs args)
        {
            if (args.NewItem == null)
            {
                RequestSyncPlayList();
                return;
            }

            NowPlaying = (int)HyPlayList.PlaybackList.CurrentItemIndex;
            if (!MPIToIndex.ContainsKey(args.NewItem))
            {
                return;
            }

            HyPlayItem hpi = List[MPIToIndex[args.NewItem]];
            AudioInfo  ai  = hpi.AudioInfo;

            hpi.AudioInfo = ai;
            //LoadSystemPlayBar(MPIToIndex[args.NewItem]);
            LoadLyrics(hpi);
            //这里为调用订阅本事件的元素
            Invoke(() => OnPlayItemChange?.Invoke(hpi));
        }
Exemplo n.º 10
0
        public static async Task <bool> AppendFile(StorageFile sf, bool nocheck163 = false)
        {
            The163KeyStruct mi;

            if (nocheck163 ||
                !The163KeyHelper.TryGetMusicInfo(TagLib.File.Create(new UwpStorageFileAbstraction(sf)).Tag, out mi))
            {
                //TagLib.File afi = TagLib.File.Create(new UwpStorageFileAbstraction(sf), ReadStyle.Average);
                var mdp = await sf.Properties.GetMusicPropertiesAsync();

                string[] contributingArtistsKey = { "System.Music.Artist" };
                IDictionary <string, object> contributingArtistsProperty =
                    await mdp.RetrievePropertiesAsync(contributingArtistsKey);

                string[] contributingArtists = contributingArtistsProperty["System.Music.Artist"] as string[];
                if (contributingArtists is null)
                {
                    contributingArtists = new[] { "未知歌手" };
                }

                AudioInfo ai = new AudioInfo()
                {
                    tag       = "本地",
                    Album     = string.IsNullOrEmpty(mdp.Album) ? "未知专辑" : mdp.Album,
                    ArtistArr = contributingArtists,
                    Artist    = string.IsNullOrEmpty(string.Join('/', contributingArtists))
                        ? "未知歌手"
                        : string.Join('/', contributingArtists),
                    LengthInMilliseconds = mdp.Duration.TotalMilliseconds,
                    SongName             = string.IsNullOrEmpty(mdp.Title) ? sf.DisplayName : mdp.Title,
                    LocalSongFile        = sf
                };

                //记载歌词
                try
                {
                    StorageFile lrcfile =
                        await(await sf.GetParentAsync()).GetFileAsync(Path.ChangeExtension(sf.Name, "lrc"));
                    ai.Lyric = await FileIO.ReadTextAsync(lrcfile);
                }
                catch (Exception)
                {
                }

                HyPlayItem hyPlayItem = new HyPlayItem()
                {
                    AudioInfo = ai,
                    isOnline  = false,
                    ItemType  = HyPlayItemType.Local,
                    Name      = ai.SongName,
                    Path      = sf.Path
                };

                List.Add(hyPlayItem);
                return(true);
            }
            else
            {
                if (string.IsNullOrEmpty(mi.musicName))
                {
                    return(await AppendFile(sf, true));
                }

                NCPlayItem hpi = new NCPlayItem()
                {
                    Album = new NCAlbum()
                    {
                        name  = mi.album,
                        id    = mi.albumId.ToString(),
                        cover = mi.albumPic
                    },
                    bitrate              = mi.bitrate,
                    hasLocalFile         = true,
                    LocalStorageFile     = sf,
                    LengthInMilliseconds = mi.duration,
                    sid      = mi.musicId.ToString(),
                    Artist   = null,
                    md5      = null,
                    size     = sf.GetBasicPropertiesAsync().GetAwaiter().GetResult().Size.ToString(),
                    songname = mi.musicName,
                    tag      = "本地"
                };
                hpi.Artist = mi.artist.Select(t => new NCArtist()
                {
                    name = t[0].ToString(), id = t[1].ToString()
                })
                             .ToList();
                AppendNCPlayItem(hpi);
                return(true);
            }
        }