private async Task InitMusicBoardAsync(MusicBoardParameter args)
        {
            try {
                is_init_progress = true;
                sid           = args.SID;
                ssid          = args.SSID;
                aid           = args.AID;
                path_url      = args.Url;
                identity_song = MHzSongBaseHelper.GetIdentity(args);
                THIS_SONG     = args.Song;

                await GetMusicDetailsAsync();

                UnregisterServiceEvents();
                RegisterServiceEvents();

                MusicSlider.ValueChanged -= MusicSlider_ValueChanged;
                MusicBoardVM.CurrentTime  = Service.Session.Position;
                MusicBoardVM.Duration     = Service.Session.NaturalDuration;
                MusicSlider.ValueChanged += MusicSlider_ValueChanged;

                MusicBoardVM.BackImage   = image;
                MusicBoardVM.LrcTitle    = title;
                MusicBoardVM.ListCount   = Service.CurrentSongList.Count;
                MusicBoardVM.CurrentItem = Service.CurrentItem;

                RandomButton.Content =
                    Service.PlayType == MusicServicePlayType.ShufflePlay ? char.ConvertFromUtf32(0xE8B1) :
                    Service.PlayType == MusicServicePlayType.AutoRepeat ? char.ConvertFromUtf32(0xE8EE) :
                    Service.PlayType == MusicServicePlayType.SingletonPlay ? char.ConvertFromUtf32(0xE8ED) :
                    char.ConvertFromUtf32(0xE84F);

                SongListButton.Content = Service.ServiceType == MusicServiceType.SongList ?
                                         char.ConvertFromUtf32(0xE142) :
                                         char.ConvertFromUtf32(0xE93E);

                if (Service.Session.PlaybackState == MediaPlaybackState.Playing)
                {
                    DoWorkWhenMusicPlayed();
                }
                else if (Service.Session.PlaybackState == MediaPlaybackState.Paused)
                {
                    DoWorkWhenMusicPaused();
                }

                MusicBoardVM.LrcList           = null;
                ChangeDownloadStatus(is_cached = await StorageHelper.IsExistLocalJsonBySHA256Async(MHzSongBaseHelper.GetIdentity(args)));
                songMessCollection             = (await LrcProcessHelper.GetSongMessageListAsync(title, artist)) ?? new List <LrcMetaData>();
            } catch {
                ReportHelper.ReportAttentionAsync(GetUIString("MediaSource_EEEEEEEError"));
            } finally { await SetDefaultLrcAndAnimationsAsync(); }
        }
        private async Task InitListResourcesAsync(int list_id)
        {
            var result = is_daily?
                         await DoubanWebProcess.GetMDoubanResponseAsync(
                path : $"{"https://"}api.douban.com/v2/fm/songlist/user_daily/?version=644&app_name=radio_android&kbps=192&apikey={APIKey}",
                host : "api.douban.com",
                reffer : null,
                bearer : bearer,
                userAgt : @"api-client/2.0 com.douban.radio/4.6.4(464) Android/18 TCL_P306C TCL TCL-306C"):
                         await DoubanWebProcess.PostDoubanResponseAsync(
                path : $"{"https://"}api.douban.com/v2/fm/songlist/{list_id}/detail",
                host : "api.douban.com",
                reffer : null,
                userAgent : @"api-client/2.0 com.douban.radio/4.6.4(464) Android/18 TCL_P306C TCL TCL-306C",
                content : new HttpFormUrlEncodedContent(new List <KeyValuePair <string, string> > {
                new KeyValuePair <string, string>("version", "644"),
                new KeyValuePair <string, string>("kbps", "320"),
                new KeyValuePair <string, string>("app_name", "radio_android"),
                new KeyValuePair <string, string>("apikey", APIKey),
            }), bearer : bearer);

            try {
                var song_list = JsonHelper.FromJson <MHzSongList>(result);
                if (song_list.Cover == "")
                {
                    song_list.Cover = "ms-appx:///Assets/231.jpg";
                }
                inner_list = new ObservableCollection <MHzSong>();
                song_list.Songs.ToList().ForEach(i => inner_list.Add(i));
                var query = await StorageHelper.GetAllStorageFilesByExtensionAsync(StorageHelper.JsonExtension);

                foreach (var item in inner_list)
                {
                    item.IsCached = StorageHelper.IsExistLocalJsonBySHA256(MHzSongBaseHelper.GetIdentity(item), query);
                }
                ListResources.Source = inner_list;
                SetListHeader(song_list);
            } catch { /* Ignore */ } finally { IncrementalLoadingBorder.SetVisibility(false); }
        }
Example #3
0
        private static async Task <bool> CreateBJSONMessageAsync(MHzSongBase song, StorageFolder folder, string filePath)
        {
            var mess_name = $"{MHzSongBaseHelper.GetIdentity(song)}.bjsonuwp";
            var mess      = default(StorageFile);

            try {
                mess = await folder.CreateFileAsync(mess_name, CreationCollisionOption.ReplaceExisting);
            } catch {
                return(false);
            }

            song.IsCached  = true;
            song.LocalPath = filePath;

            try {
                var bytes = default(byte[]);
                if (song is MHzSong)
                {
                    bytes = Encoding.UTF8.GetBytes(JsonHelper.ToJson(song as MHzSong));
                }
                else
                {
                    bytes = Encoding.UTF8.GetBytes(JsonHelper.ToJson(song));
                }
                using (var irandom = await mess.OpenAsync(FileAccessMode.ReadWrite)) {
                    var stream = irandom.AsStreamForWrite();
                    await stream.WriteAsync(bytes, 0, bytes.Length);

                    await stream.FlushAsync();
                }
            } catch (SerializationException) {
                return(false);
            }

            return(true);
        }
Example #4
0
        public async static Task <MediaPlaybackItem> CreatePlayItemAsync(Uri uri, Uri img, MusicBoardParameter para, string title, string artist, string albumTitle, string albunmArtist)
        {
            var storage = await StorageHelper.FetchLocalMusicBySHA256Async(MHzSongBaseHelper.GetIdentity(para));

            var source = default(MediaSource);

            source = storage != null?MediaSource.CreateFromStorageFile(storage) : MediaSource.CreateFromUri(uri);

            source.CustomProperties["Title"]      = title;
            source.CustomProperties["CheckPoint"] = SetCheckPoint(UTCPoint);
            source.CustomProperties["SHA256"]     = para.SHA256;
            source.CustomProperties["Message"]    = para;
            var item       = new MediaPlaybackItem(source);
            var properties = item.GetDisplayProperties();

            properties.Type                        = Windows.Media.MediaPlaybackType.Music;
            properties.Thumbnail                   = RandomAccessStreamReference.CreateFromUri(img);
            properties.MusicProperties.Title       = title;
            properties.MusicProperties.Artist      = artist;
            properties.MusicProperties.AlbumTitle  = albumTitle;
            properties.MusicProperties.AlbumArtist = albunmArtist;
            item.ApplyDisplayProperties(properties);
            return(item);
        }
Example #5
0
        public async Task <DownloadResult> DownloadMusicAsync(MHzSongBase song, bool not_show = false, bool show_start = true, bool show_succ_notif = true, bool show_fail_notif = true)
        {
            var file = default(StorageFile);

            try {
                var folder = await GetBeansproutMusicFolderAsync();

                var filename = MHzSongBaseHelper.GetIdentity(song) + StorageHelper.MusicTemporaryExtension;
                file = await CreateFileInMusicFolderWithNameAsync(folder, filename);

                var fail_toast = ToastHelper.CreateToastNotificaion(
                    title: GetUIString("Download_Failed") + " : " + song.Title,
                    content: DateTime.Now.ToString("h:mm tt"),
                    imageUri: " -- ",
                    uri: " -- ",
                    logoOverride: song.Picture,
                    voice: "ms-appx:///Voice/yellsedtsr.mp3");

                var succeed_toast = ToastHelper.CreateToastNotificaion(
                    title: GetUIString("Download_Succeed") + " : " + song.Title,
                    content: DateTime.Now.ToString("h:mm tt"),
                    imageUri: " -- ",
                    uri: " -- ",
                    logoOverride: song.Picture,
                    voice: "ms-appx:///Voice/haizi.mp3");

                var group = BackgroundTransferGroup.CreateGroup(DoubanMusicGroup);
                group.TransferBehavior = BackgroundTransferBehavior.Serialized;

                var downloader = new BackgroundDownloader {
                    FailureToastNotification = show_succ_notif ? new Windows.UI.Notifications.ToastNotification(fail_toast) : null,
                    SuccessToastNotification = show_fail_notif ? new Windows.UI.Notifications.ToastNotification(succeed_toast) : null,
                    TransferGroup            = group,
                };

                var succeed_trans = Uri.TryCreate(song.Url, UriKind.Absolute, out var do_url);
                if (!succeed_trans)
                {
                    throw new DownloadCanNotRunException();
                }

                var operation = downloader.CreateDownload(do_url, file);
                operation.CostPolicy = BackgroundTransferCostPolicy.UnrestrictedOnly;

                if (show_start)
                {
                    ReportHelper.ReportAttentionAsync(GetUIString("Download_Start"));
                }

                if (!not_show)
                {
                    DownloadListAddNewItem(song, operation);
                    operation = await operation.StartAsync();
                }
                else
                {
                    var control = await operation.StartAsync();
                }

                var mess_succeed = await CreateBJSONMessageAsync(song, folder, file.Path);

                if (!mess_succeed)
                {
                    throw new JSONCanNotCreateException();
                }

                await file.RenameAsync(filename.Replace(StorageHelper.MusicTemporaryExtension, StorageHelper.MusicExtension), NameCollisionOption.ReplaceExisting);

                return(DownloadResult.Successfully);
            } catch (JSONCanNotCreateException) {
                await file.DeleteAsync();

                return(DownloadResult.Failed);
            } catch (DownloadCanNotRunException) {
                await file.DeleteAsync();

                return(DownloadResult.Failed);
            } catch (FileCannNotCreateException) {
                return(DownloadResult.Failed);
            } catch (FileExistException) {
                return(DownloadResult.FileExist);
            } catch (Exception e) {
                Debug.WriteLine(e.Message);
                return(DownloadResult.Failed);
            }
        }