コード例 #1
0
        public async void Initialize()
        {
            try
            {
                radio = await Minorhythm.Load();
            }
            catch (TypeInitializationException)
            {
                Messenger.Raise(new InformationMessage
                    ("radio minorhythm から情報を読み込めませんでした。",
                    "エラー",
                    MessageBoxImage.Error,
                    "LoadError"));
                return;
            }
            if (radio == null)
            {
                await Messenger.RaiseAsync(new InformationMessage
                    ("ネットワーク接続が無効です。",
                    "エラー",
                    MessageBoxImage.Error,
                    "NetoworkError"));
                return;
            }
            RaisePropertyChanged("Radio");
            ToggleCornersCommand.RaiseCanExecuteChanged();
            ToggleThemeSongCommand.RaiseCanExecuteChanged();

            player = new MediaPlayer();
            player.BufferingStarted += (s, e) => PlayerState = State.バッファ中;
            player.BufferingEnded += (s, e) => PlayerState = State.再生中;
            player.MediaOpened += (s, e) => IsInitializedRadio = true;
            player.MediaEnded += (s, e) =>
            {
                player.Close();
                PlayerState = State.停止中;
            };
            playImageAddress = "../Resources/Play.png";
            pauseImageAddress = "../Resources/Pause.png";
            SelectedContent = radio.Contents.First();
            seakTimer = new DispatcherTimer(TimeSpan.FromMilliseconds(100),
                                            DispatcherPriority.DataBind,
                                            (s, e) => { RaisePropertyChanged("PlayingTime"); RaisePropertyChanged("SeakPosition"); },
                                            DispatcherHelper.UIDispatcher);
            seakTimer.Start();
        }
コード例 #2
0
        /// <summary>
        /// radio minorhythm の情報を読み込み、新しいインスタンスを初期化して返します。
        /// </summary>
        public static async Task<Minorhythm> Load()
        {
            if (!NetworkInterface.GetIsNetworkAvailable()) return null;

            var radio = new Minorhythm();
            try
            {
                await radio.Initialize();
            }
            catch(Exception ex)
            {
                Logger.WriteError(ex);
                throw new TypeInitializationException(radio.GetType().FullName, ex);
            }

            return radio;
        }