Beispiel #1
0
 public void DisposeScene()
 {
     keepPlaying = false;
     OutputDevice.Stop();
     OutputDevice.PlaybackStopped -= SongStopped;
     audioFile.Seek(0, System.IO.SeekOrigin.Begin);
 }
Beispiel #2
0
 public void DisposeScene()
 {
     CameraYPosition = 0;
     keepPlaying     = false;
     OutputDevice.Stop();
     OutputDevice.PlaybackStopped -= SongStopped;
     audioFile.Seek(0, System.IO.SeekOrigin.Begin);
     IsDisposed = true;
 }
Beispiel #3
0
        public override void run()
        {
            try
            {
                // Device ID cannot be changed after init, so we will init here in case there is a live update.
                wavePlayer.Pause();
                audioFileReader.Seek(0, System.IO.SeekOrigin.Begin);
                wavePlayer.Init(audioFileReader);
                wavePlayer.Play();
            }

            catch (NAudio.MmException e)
            {
                GAVPI.ProfileDebugLog.Entry("[ ! ] Error Details: " + e.Message);
                this.LogError();

                // NAudio always throws MmExceptions so we parse from the message for this case.
                if (e.Message.Equals("BadDeviceId calling waveOutOpen"))
                {
                    GAVPI.ProfileDebugLog.Entry("[...] Attempting to playback via default device next time.");

                    // A little self healing, it's likely that device was unplugged or
                    // changed in some way since the profie has been loaded.
                    wavout = new WaveOut();
                    wavout.DeviceNumber = defaultDeviceID;
                    wavePlayer          = wavout;
                    audioFileReader     = new AudioFileReader(this.value);
                }
            }
            catch (Exception e)
            {
                GAVPI.ProfileDebugLog.Entry("[ ! ] Error Details: " + e.Message);
                this.LogError();
            }
        }
 private void Device_PlaybackStopped(object sender, StoppedEventArgs e)
 {
     if (IsClosed)
     {
         return;
     }
     if (data.NotifySoundRepeatCount > -1)
     {
         PlaybackCount++;
         if (data.NotifySoundRepeatCount == PlaybackCount)
         {
             return;
         }
     }
     file.Seek(0, System.IO.SeekOrigin.Begin);
     device.Play();
 }
Beispiel #5
0
        public AudioPlayer(string url, bool loop = false, float?volum = null)
        {
            if (volum == null)
            {
                volum = SharedSetting.BGMVolum;
            }
            PlayThread = new Thread(() =>
            {
                string path_rele = PackStream.Locate(url);
                var audioFile    = new AudioFileReader(path_rele);
                outputDevice     = new WaveOutEvent();
                outputDevice.Init(audioFile);
                outputDevice.Volume = (float)volum;
                do
                {
                    outputDevice.Play(); // 异步执行
                    while (outputDevice.PlaybackState == PlaybackState.Playing)
                    {
                        Thread.Sleep(100);
                        if (!canplay)
                        {
                            break;
                        }
                    }
                    outputDevice.Stop();
                    audioFile.Seek(0, SeekOrigin.Begin);
                } while (loop && canplay);

                outputDevice.Dispose();
                audioFile.Close();
                audioFile.Dispose();
                try
                {
                    File.Delete(path_rele);
                }
                catch
                {
                }
            })
            {
                IsBackground = true
            };
            PlayThread.Start();
        }
 private void Mixer_MixerInputEnded(object sender, SampleProviderEventArgs e)
 {
     if (!IsInPlay)
     {
         return;
     }
     if (e.SampleProvider is MainBGMSampleProvider)
     {
         mainAudioFile.Seek(0, System.IO.SeekOrigin.Begin);
         mixer.AddMixerInput(new MainBGMSampleProvider(mainAudioSample));
     }
     else if (e.SampleProvider is RightSESampleProvider)
     {
         LocateNewSE(true);
     }
     else
     {
         LocateNewSE(false);
     }
 }
Beispiel #7
0
 /// <summary>
 /// Stops this instance.
 /// </summary>
 public void Stop()
 {
     RemoveInput();
     inputStream.Seek(0, SeekOrigin.Begin);
     isStopped = true;
 }
Beispiel #8
0
 /// <summary>
 /// Play and seek in this song.
 /// </summary>
 /// <param name="seek">The amount to seek in milliseconds.</param>
 public void Play(int seek)
 {
     reader.Seek(provider.WaveFormat.AverageBytesPerSecond * (seek / 1000), SeekOrigin.Begin);
     Play();
 }