mirror of
https://github.com/crskycode/GARbro.git
synced 2024-11-27 15:44:00 +08:00
dispose audio input when playback is stopped.
This commit is contained in:
parent
50eb805cd2
commit
460f6b4447
@ -120,6 +120,7 @@ namespace GARbro.GUI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
protected override void OnClosing (CancelEventArgs e)
|
protected override void OnClosing (CancelEventArgs e)
|
||||||
{
|
{
|
||||||
|
AudioDevice = null;
|
||||||
CurrentAudio = null;
|
CurrentAudio = null;
|
||||||
SaveSettings();
|
SaveSettings();
|
||||||
base.OnClosing (e);
|
base.OnClosing (e);
|
||||||
@ -811,27 +812,40 @@ namespace GARbro.GUI
|
|||||||
return File.OpenRead (Path.Combine (vm.Path, entry.Name));
|
return File.OpenRead (Path.Combine (vm.Path, entry.Name));
|
||||||
}
|
}
|
||||||
|
|
||||||
WaveOutEvent m_audio;
|
WaveOutEvent m_audio_device;
|
||||||
WaveOutEvent CurrentAudio
|
WaveOutEvent AudioDevice
|
||||||
{
|
{
|
||||||
get { return m_audio; }
|
get { return m_audio_device; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (m_audio != null)
|
if (m_audio_device != null)
|
||||||
m_audio.Dispose();
|
m_audio_device.Dispose();
|
||||||
m_audio = value;
|
m_audio_device = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WaveStream m_audio_input;
|
||||||
|
WaveStream CurrentAudio
|
||||||
|
{
|
||||||
|
get { return m_audio_input; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (m_audio_input != null)
|
||||||
|
m_audio_input.Dispose();
|
||||||
|
m_audio_input = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PlayFile (Entry entry)
|
private void PlayFile (Entry entry)
|
||||||
{
|
{
|
||||||
|
SoundInput sound = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SetBusyState();
|
SetBusyState();
|
||||||
using (var input = OpenEntry (entry))
|
using (var input = OpenEntry (entry))
|
||||||
{
|
{
|
||||||
FormatCatalog.Instance.LastError = null;
|
FormatCatalog.Instance.LastError = null;
|
||||||
var sound = AudioFormat.Read (input);
|
sound = AudioFormat.Read (input);
|
||||||
if (null == sound)
|
if (null == sound)
|
||||||
{
|
{
|
||||||
if (null != FormatCatalog.Instance.LastError)
|
if (null != FormatCatalog.Instance.LastError)
|
||||||
@ -839,17 +853,17 @@ namespace GARbro.GUI
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CurrentAudio != null)
|
if (AudioDevice != null)
|
||||||
{
|
{
|
||||||
CurrentAudio.PlaybackStopped -= OnPlaybackStopped;
|
AudioDevice.PlaybackStopped -= OnPlaybackStopped;
|
||||||
CurrentAudio = null;
|
AudioDevice = null;
|
||||||
}
|
}
|
||||||
var wave_stream = new WaveStreamImpl (sound);
|
CurrentAudio = new WaveStreamImpl (sound);
|
||||||
CurrentAudio = new WaveOutEvent();
|
AudioDevice = new WaveOutEvent();
|
||||||
CurrentAudio.Init (wave_stream);
|
AudioDevice.Init (CurrentAudio);
|
||||||
CurrentAudio.PlaybackStopped += OnPlaybackStopped;
|
AudioDevice.PlaybackStopped += OnPlaybackStopped;
|
||||||
CurrentAudio.Play();
|
AudioDevice.Play();
|
||||||
var fmt = wave_stream.WaveFormat;
|
var fmt = CurrentAudio.WaveFormat;
|
||||||
SetResourceText (string.Format ("Playing {0} / {2}bps / {1}Hz", entry.Name,
|
SetResourceText (string.Format ("Playing {0} / {2}bps / {1}Hz", entry.Name,
|
||||||
fmt.SampleRate, sound.SourceBitrate / 1000));
|
fmt.SampleRate, sound.SourceBitrate / 1000));
|
||||||
}
|
}
|
||||||
@ -857,12 +871,15 @@ namespace GARbro.GUI
|
|||||||
catch (Exception X)
|
catch (Exception X)
|
||||||
{
|
{
|
||||||
SetStatusText (X.Message);
|
SetStatusText (X.Message);
|
||||||
|
if (null != sound)
|
||||||
|
sound.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPlaybackStopped (object sender, StoppedEventArgs e)
|
private void OnPlaybackStopped (object sender, StoppedEventArgs e)
|
||||||
{
|
{
|
||||||
SetResourceText ("");
|
SetResourceText ("");
|
||||||
|
CurrentAudio = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -930,6 +947,7 @@ namespace GARbro.GUI
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
m_app.ResetCache();
|
m_app.ResetCache();
|
||||||
|
ResetPreviewPane();
|
||||||
if (!items.Skip (1).Any()) // items.Count() == 1
|
if (!items.Skip (1).Any()) // items.Count() == 1
|
||||||
{
|
{
|
||||||
string item_name = Path.Combine (CurrentPath, items.First().Name);
|
string item_name = Path.Combine (CurrentPath, items.First().Name);
|
||||||
|
Loading…
Reference in New Issue
Block a user