예제 #1
0
 public void DisposeScene()
 {
     keepPlaying = false;
     OutputDevice.Stop();
     OutputDevice.PlaybackStopped -= SongStopped;
     audioFile.Seek(0, System.IO.SeekOrigin.Begin);
 }
예제 #2
0
 public void DisposeScene()
 {
     CameraYPosition = 0;
     keepPlaying     = false;
     OutputDevice.Stop();
     OutputDevice.PlaybackStopped -= SongStopped;
     audioFile.Seek(0, System.IO.SeekOrigin.Begin);
     IsDisposed = true;
 }
예제 #3
0
파일: Action.cs 프로젝트: zhuangzard/AVPI
        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();
            }
        }
예제 #4
0
 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();
 }
예제 #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();
        }
예제 #6
0
 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);
     }
 }
예제 #7
0
 /// <summary>
 /// Stops this instance.
 /// </summary>
 public void Stop()
 {
     RemoveInput();
     inputStream.Seek(0, SeekOrigin.Begin);
     isStopped = true;
 }
예제 #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();
 }