private async void Ring(object obj) { MobileDebug.Service.WriteEvent("Ring"); if (!library.IsPlaying) { return; } State = RingerState.Waiting; await Task.Delay(millisAroundRing); if (State != RingerState.Waiting) { return; } double millisUntilCurrentSongEnds = BackgroundMediaPlayer.Current.NaturalDuration.TotalMilliseconds - BackgroundMediaPlayer.Current.Position.TotalMilliseconds; if (millisUntilCurrentSongEnds < millisAroundRing) { return; } await SetCurrent(); }
public async Task SetCurrent() { if (!library.IsPlaying || State == RingerState.Ringing) { return; } task.PlayerType = BackgroundPlayerType.Ringer; try { MobileDebug.Service.WriteEvent("RingFileGet"); Uri uri = new Uri("ms-appx:///Assets/Glockenschlag.mp3"); StorageFile file = await GetRingerFile(uri); try { State = RingerState.Ringing; BackgroundMediaPlayer.Current.Volume = 1; BackgroundMediaPlayer.Current.AutoPlay = true; BackgroundMediaPlayer.Current.SetFileSource(file); } catch (Exception e) { MobileDebug.Service.WriteEvent("RingFileFail1", e); task.PlayerType = BackgroundPlayerType.Music; await task.BackgroundPlayer.SetCurrent(); } } catch (Exception e) { MobileDebug.Service.WriteEvent("RingFileFaFileName", e); } }
public async Task MediaFailed(MediaPlayer sender, MediaPlayerFailedEventArgs args) { State = RingerState.Idle; task.PlayerType = BackgroundPlayerType.Music; await task.BackgroundPlayer.SetCurrent(); }
public void MediaOpened(MediaPlayer sender, object args) { State = RingerState.Ringing; //sender.Volume = 1; //do //{ // sender.Play(); // Task.Delay(1000).Wait(); // FolderMusicDebug.DebugEvent.SaveText("OpenRing", sender.CurrentState); //} //while (sender.CurrentState != MediaPlayerState.Playing); }