public void StartFadingOut() { GetComponent <AudioSource>().volume = cachedMaxVolume; mode = MusicPlayerMode.FadingOut; timer = fadeOutTime; }
public void StartPlaying() { GetComponent <AudioSource>().volume = cachedMaxVolume; mode = MusicPlayerMode.Playing; timer = Mathf.Max(0.0f, GetComponent <AudioSource>().clip.length - fadeInTime - fadeOutTime); }
public void StartFadingIn(AudioClip clip) { GetComponent <AudioSource>().clip = clip; GetComponent <AudioSource>().volume = 0.0f; if (!GetComponent <AudioSource>().isPlaying) { GetComponent <AudioSource>().Play(); } mode = MusicPlayerMode.FadingIn; timer = fadeInTime; }
public static void Update(MusicPlayerMode mode) { if (mode == MusicPlayerMode.Disabled) { if (XnaMedia.MediaPlayer.State == XnaMedia.MediaState.Playing) { XnaMedia.MediaPlayer.Pause(); } return; } XnaMedia.MediaPlayer.Volume = mode == MusicPlayerMode.Normal ? MaxSoundVolume : MinSoundVolume; if (XnaMedia.MediaPlayer.State == XnaMedia.MediaState.Playing && mode == MusicPlayerMode.Normal && XnaMedia.MediaPlayer.Volume < MaxSoundVolume) { XnaMedia.MediaPlayer.Volume += SoundVolumeStep; XnaMedia.MediaPlayer.Volume = Math.Min(XnaMedia.MediaPlayer.Volume, MaxSoundVolume); } else if (XnaMedia.MediaPlayer.State == XnaMedia.MediaState.Playing && mode == MusicPlayerMode.LowVolume && XnaMedia.MediaPlayer.Volume > MinSoundVolume) { XnaMedia.MediaPlayer.Volume -= SoundVolumeStep; XnaMedia.MediaPlayer.Volume = Math.Max(XnaMedia.MediaPlayer.Volume, MinSoundVolume); } else if (XnaMedia.MediaPlayer.State == XnaMedia.MediaState.Paused) { XnaMedia.MediaPlayer.Resume(); } else if (XnaMedia.MediaPlayer.State == XnaMedia.MediaState.Stopped && _currentSong != null || XnaMedia.MediaPlayer.State == XnaMedia.MediaState.Playing && !_currentSong.Playing) { _currentSongIndex = ++_currentSongIndex % Songs.Count; _currentSong = Songs.Any() ? Songs[_currentSongIndex] : null; Start(_currentSong); } else if (mode != MusicPlayerMode.Disabled && XnaMedia.MediaPlayer.State == XnaMedia.MediaState.Stopped) { _currentSongIndex = 0; _currentSong = Songs.FirstOrDefault(); Start(_currentSong); } }
private static void MusicPlayerDemo(MusicPlayerMode musicPlayerMode) { const string fileName = "simple_audio.mp3"; MusicPlayer musicPlayer = new MusicPlayer(); switch (musicPlayerMode) { case MusicPlayerMode.Mp3: musicPlayer = new MusicPlayer(fileName); break; case MusicPlayerMode.Bytes: var bytes = File.ReadAllBytes(fileName); musicPlayer = new MusicPlayer(bytes); break; case MusicPlayerMode.Stream: var stream = File.OpenRead(fileName); musicPlayer = new MusicPlayer(stream); break; } var delay = 4000; musicPlayer.Play(); System.Threading.Thread.Sleep(delay); musicPlayer.Pause(); System.Threading.Thread.Sleep(delay); musicPlayer.Play(); System.Threading.Thread.Sleep(delay); musicPlayer.Stop(); System.Threading.Thread.Sleep(delay); musicPlayer.Play(); System.Threading.Thread.Sleep(delay); musicPlayer.Closed(); Console.ReadKey(); }