mirror of
https://github.com/crskycode/GARbro.git
synced 2024-11-23 13:45:34 +08:00
(PlayFile): merged nested try blocks.
This commit is contained in:
parent
df70fc9271
commit
342b96da22
@ -965,48 +965,41 @@ namespace GARbro.GUI
|
|||||||
|
|
||||||
private void PlayFile (Entry entry)
|
private void PlayFile (Entry entry)
|
||||||
{
|
{
|
||||||
|
IBinaryStream input = null;
|
||||||
SoundInput sound = null;
|
SoundInput sound = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SetBusyState();
|
SetBusyState();
|
||||||
var input = VFS.OpenBinaryStream (entry);
|
input = VFS.OpenBinaryStream (entry);
|
||||||
try
|
FormatCatalog.Instance.LastError = null;
|
||||||
|
sound = AudioFormat.Read (input);
|
||||||
|
if (null == sound)
|
||||||
{
|
{
|
||||||
FormatCatalog.Instance.LastError = null;
|
if (null != FormatCatalog.Instance.LastError)
|
||||||
sound = AudioFormat.Read (input);
|
throw FormatCatalog.Instance.LastError;
|
||||||
if (null == sound)
|
return;
|
||||||
{
|
}
|
||||||
if (null != FormatCatalog.Instance.LastError)
|
|
||||||
throw FormatCatalog.Instance.LastError;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (AudioDevice != null)
|
if (AudioDevice != null)
|
||||||
{
|
|
||||||
AudioDevice.PlaybackStopped -= OnPlaybackStopped;
|
|
||||||
AudioDevice = null;
|
|
||||||
}
|
|
||||||
CurrentAudio = new WaveStreamImpl (sound);
|
|
||||||
AudioDevice = new WaveOutEvent();
|
|
||||||
// conversion to sample provider somehow removes crackling at the end of WAV sound clips.
|
|
||||||
if ("wav" == sound.SourceFormat || 8 == sound.Format.BitsPerSample)
|
|
||||||
AudioDevice.Init (CurrentAudio.ToSampleProvider());
|
|
||||||
else
|
|
||||||
AudioDevice.Init (CurrentAudio);
|
|
||||||
AudioDevice.PlaybackStopped += OnPlaybackStopped;
|
|
||||||
AudioDevice.Play();
|
|
||||||
appPlaybackControl.Visibility = Visibility.Visible;
|
|
||||||
var fmt = CurrentAudio.WaveFormat;
|
|
||||||
SetResourceText (string.Format (guiStrings.MsgPlaying, entry.Name,
|
|
||||||
fmt.SampleRate, sound.SourceBitrate / 1000,
|
|
||||||
CurrentAudio.TotalTime.ToString ("m':'ss")));
|
|
||||||
input = null;
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
{
|
||||||
if (input != null)
|
AudioDevice.PlaybackStopped -= OnPlaybackStopped;
|
||||||
input.Dispose();
|
AudioDevice = null;
|
||||||
}
|
}
|
||||||
|
CurrentAudio = new WaveStreamImpl (sound);
|
||||||
|
AudioDevice = new WaveOutEvent();
|
||||||
|
// conversion to sample provider somehow removes crackling at the end of WAV sound clips.
|
||||||
|
if ("wav" == sound.SourceFormat || 8 == sound.Format.BitsPerSample)
|
||||||
|
AudioDevice.Init (CurrentAudio.ToSampleProvider());
|
||||||
|
else
|
||||||
|
AudioDevice.Init (CurrentAudio);
|
||||||
|
AudioDevice.PlaybackStopped += OnPlaybackStopped;
|
||||||
|
AudioDevice.Play();
|
||||||
|
appPlaybackControl.Visibility = Visibility.Visible;
|
||||||
|
var fmt = CurrentAudio.WaveFormat;
|
||||||
|
SetResourceText (string.Format (guiStrings.MsgPlaying, entry.Name,
|
||||||
|
fmt.SampleRate, sound.SourceBitrate / 1000,
|
||||||
|
CurrentAudio.TotalTime.ToString ("m':'ss")));
|
||||||
|
input = null;
|
||||||
}
|
}
|
||||||
catch (Exception X)
|
catch (Exception X)
|
||||||
{
|
{
|
||||||
@ -1014,6 +1007,11 @@ namespace GARbro.GUI
|
|||||||
if (null != sound)
|
if (null != sound)
|
||||||
sound.Dispose();
|
sound.Dispose();
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (input != null)
|
||||||
|
input.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StopPlaybackExec (object sender, ExecutedRoutedEventArgs e)
|
private void StopPlaybackExec (object sender, ExecutedRoutedEventArgs e)
|
||||||
|
Loading…
Reference in New Issue
Block a user