예제 #1
0
 public static IAsyncOperation <InternetRadioConfig> GetDefault()
 {
     return(Task.Run(async() =>
     {
         var config = new InternetRadioConfig();
         await config.LoadAsync();
         return config;
     }).AsAsyncOperation());
 }
예제 #2
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            deferral = taskInstance.GetDeferral();
            taskInstance.Canceled += TaskInstance_Canceled;

            var config = await InternetRadioConfig.GetDefault();

            _bot = new Bot(config.Key, config.Owner, config.RadioLink);

            await ThreadPool.RunAsync(_ => _bot.Start());

            if (null == s_radioManager)
            {
                s_radioManager = new RadioManager();
                await s_radioManager.Initialize(config, _bot);
            }
        }
예제 #3
0
        public IAsyncAction Initialize(InternetRadioConfig config, Bot bot)
        {
            _bot = bot;
            bot.RadioChangeRequest += RadioUriChanged;
            bot.CommandRequest     += CommandChanged;

            var radioTask = Task.Run(async() =>
            {
                _config          = config;
                _playbackRetries = 0;

                _radioPowerManager = new RadioPowerManager();
                _radioPowerManager.PowerStateChanged += RadioPowerManager_PowerStateChanged;

                _radioPlaybackManager = new MediaEnginePlaybackManager();
                _radioPlaybackManager.VolumeChanged        += RadioPlaybackManager_VolumeChanged;
                _radioPlaybackManager.PlaybackStateChanged += RadioPlaybackManager_PlaybackStateChanged;
                await _radioPlaybackManager.InitialzeAsync();

                // Manage settings
                var savedVolume = LoadSettings("volume");
                if (savedVolume == null)
                {
                    savedVolume = ".1";
                }
                _radioPlaybackManager.Volume = Convert.ToDouble(savedVolume);

                // Wake up the radio
                _radioPowerManager.PowerState = PowerState.Powered;

                var uriToPlay = LoadSettings("play");
                if (uriToPlay != null)
                {
                    currentUri = uriToPlay;
                }
            });

            return(radioTask.AsAsyncAction());
        }