(MainWindow) 1. Next/Previous functionality. 2. Fix StopPlayback bug for multiple-file playback

This commit is contained in:
andylinpersonal 2018-02-10 02:36:44 +08:00
parent 44a90b3fed
commit 5ca4bcb22c
2 changed files with 93 additions and 37 deletions

View File

@ -273,28 +273,48 @@
</StatusBarItem> </StatusBarItem>
<Separator Width="1"/> <Separator Width="1"/>
<!-- ADL --> <!-- ADL -->
<!-- TODO <StatusBarItem x:Name="appPreviousAudioControl" Visibility="Collapsed">
<Button Width="18" Height="18"
<StatusBarItem x:Name="appNextControl" Visibility="Visible">
<Button x:Name="btn_appPauseControl" Width="18" Height="18"
HorizontalContentAlignment="Center" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
Command="{x:Static local:Commands.AudioPauseContinue}"> Command="{x:Static local:Commands.AudioPrevious}">
<Canvas HorizontalAlignment="Center" VerticalAlignment="Center" FlowDirection="RightToLeft">
<Path Stroke="Black" StrokeThickness ="2" Canvas.Left="-5" Canvas.Top="-4">
<Path.Data>
<PathGeometry>
<PathFigure StartPoint="2,0">
<LineSegment Point="2,8"></LineSegment>
</PathFigure>
</PathGeometry>
</Path.Data>
</Path>
<Polygon Fill="Black" Stretch="None" Points="0,0 0,8 6,4" Canvas.Left="0" Canvas.Top="-4" />
</Canvas>
</Button> </Button>
</StatusBarItem> </StatusBarItem>
<StatusBarItem x:Name="appPreviousControl" Visibility="Visible"> <StatusBarItem x:Name="appNextAudioControl" Visibility="Collapsed">
<Button x:Name="btn_appPauseControl" Width="18" Height="18" <Button Width="18" Height="18"
HorizontalContentAlignment="Center" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
Command="{x:Static local:Commands.AudioPauseContinue}"> Command="{x:Static local:Commands.AudioNext}">
<Canvas HorizontalAlignment="Center" VerticalAlignment="Center">
<Path Stroke="Black" StrokeThickness ="2" Canvas.Left="-5" Canvas.Top="-4">
<Path.Data>
<PathGeometry>
<PathFigure StartPoint="2,0">
<LineSegment Point="2,8"></LineSegment>
</PathFigure>
</PathGeometry>
</Path.Data>
</Path>
<Polygon Fill="Black" Stretch="None" Points="0,0 0,8 6,4" Canvas.Left="0" Canvas.Top="-4" />
</Canvas>
</Button> </Button>
</StatusBarItem> </StatusBarItem>
<StatusBarItem x:Name="appPauseAudioControl" Visibility="Collapsed">
-->
<StatusBarItem x:Name="appPauseControl" Visibility="Collapsed">
<Button x:Name="btn_appPauseControl" Width="18" Height="18" <Button x:Name="btn_appPauseControl" Width="18" Height="18"
HorizontalContentAlignment="Center" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
Command="{x:Static local:Commands.AudioPauseContinue}"> Command="{x:Static local:Commands.AudioPauseContinue}">
<!-- click to pause <!-- click to pause-->
<Path Stroke="Black" StrokeThickness="3"> <Path Stroke="Black" StrokeThickness="3">
<Path.Data> <Path.Data>
@ -307,7 +327,7 @@
</PathFigure> </PathFigure>
</PathGeometry> </PathGeometry>
</Path.Data> </Path.Data>
</Path>--> </Path>
<!-- Click to continue <!-- Click to continue
@ -318,7 +338,8 @@
<StatusBarItem x:Name="appPlaybackControl" Visibility="Collapsed"> <StatusBarItem x:Name="appPlaybackControl" Visibility="Collapsed">
<Button Width="18" Height="18" <Button Width="18" Height="18"
HorizontalContentAlignment="Center" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
Command="{x:Static local:Commands.StopPlayback}"> Command="{x:Static local:Commands.AudioStopAll}">
<!--ADL-->
<Rectangle Stretch="Fill" Fill="Black" Width="8" Height="8"/> <Rectangle Stretch="Fill" Fill="Black" Width="8" Height="8"/>
</Button> </Button>
</StatusBarItem> </StatusBarItem>
@ -489,6 +510,8 @@
<CommandBinding Command="{x:Static local:Commands.AudioPlayAll}" Executed="AudioPlayAllExec" CanExecute="CanAudioPlayAllExec"/> <CommandBinding Command="{x:Static local:Commands.AudioPlayAll}" Executed="AudioPlayAllExec" CanExecute="CanAudioPlayAllExec"/>
<CommandBinding Command="{x:Static local:Commands.AudioStopAll}" Executed="AudioStopAllExec" CanExecute="CanAudioStopAllExec"/> <CommandBinding Command="{x:Static local:Commands.AudioStopAll}" Executed="AudioStopAllExec" CanExecute="CanAudioStopAllExec"/>
<CommandBinding Command="{x:Static local:Commands.AudioPauseContinue}" Executed="AudioPauseContinueExec" CanExecute="CanAudioPauseContinueExec"/> <CommandBinding Command="{x:Static local:Commands.AudioPauseContinue}" Executed="AudioPauseContinueExec" CanExecute="CanAudioPauseContinueExec"/>
<CommandBinding Command="{x:Static local:Commands.AudioNext}" Executed="AudioNextExec" CanExecute="CanAudioNextExec"/>
<CommandBinding Command="{x:Static local:Commands.AudioPrevious}" Executed="AudioPreviousExec" CanExecute="CanAudioPreviousExec"/>
</Window.CommandBindings> </Window.CommandBindings>
</Window> </Window>

View File

@ -65,6 +65,7 @@ namespace GARbro.GUI
const StringComparison StringIgnoreCase = StringComparison.CurrentCultureIgnoreCase; const StringComparison StringIgnoreCase = StringComparison.CurrentCultureIgnoreCase;
#region ADL #region ADL
Icon app_icon = new Icon(Application.GetResourceStream(new Uri("pack://application:,,,/images/sample.ico")).Stream); Icon app_icon = new Icon(Application.GetResourceStream(new Uri("pack://application:,,,/images/sample.ico")).Stream);
TaskbarIcon tray = new TaskbarIcon(); TaskbarIcon tray = new TaskbarIcon();
Form.Timer hide_timer = null; Form.Timer hide_timer = null;
@ -100,7 +101,7 @@ namespace GARbro.GUI
tray.ToolTipText = msg; tray.ToolTipText = msg;
} }
#endregion #endregion
public MainWindow() public MainWindow()
{ {
@ -129,7 +130,7 @@ namespace GARbro.GUI
}; };
pathLine.EnterKeyDown += acb_OnKeyDown; pathLine.EnterKeyDown += acb_OnKeyDown;
#region ADL #region ADL
var ico = new Icon(Application.GetResourceStream(new Uri("pack://application:,,,/images/sample.ico")).Stream); var ico = new Icon(Application.GetResourceStream(new Uri("pack://application:,,,/images/sample.ico")).Stream);
tray.Icon = app_icon; tray.Icon = app_icon;
tray.ToolTipText = guiStrings.MsgRunning; tray.ToolTipText = guiStrings.MsgRunning;
@ -172,7 +173,7 @@ namespace GARbro.GUI
pathGeometry.Figures.Add(line1); pathGeometry.Figures.Add(line1);
m_btnContinue_state_pause.Data = pathGeometry; m_btnContinue_state_pause.Data = pathGeometry;
} }
#endregion #endregion
} }
void WindowLoaded (object sender, RoutedEventArgs e) void WindowLoaded (object sender, RoutedEventArgs e)
@ -461,7 +462,7 @@ namespace GARbro.GUI
} }
} }
#region Refresh view on filesystem changes #region Refresh view on filesystem changes
private FileSystemWatcher m_watcher = new FileSystemWatcher(); private FileSystemWatcher m_watcher = new FileSystemWatcher();
@ -500,7 +501,7 @@ namespace GARbro.GUI
Dispatcher.Invoke (RefreshView); Dispatcher.Invoke (RefreshView);
} }
} }
#endregion #endregion
/// <summary> /// <summary>
/// Select specified item within CurrentDirectory and bring it into a view. /// Select specified item within CurrentDirectory and bring it into a view.
@ -845,7 +846,7 @@ namespace GARbro.GUI
} }
} }
#region Navigation history implementation #region Navigation history implementation
internal string CurrentPath { get { return ViewModel.Path.First(); } } internal string CurrentPath { get { return ViewModel.Path.First(); } }
@ -916,7 +917,7 @@ namespace GARbro.GUI
{ {
e.CanExecute = m_history.CanRedo(); e.CanExecute = m_history.CanRedo();
} }
#endregion #endregion
private void OpenFileExec (object control, ExecutedRoutedEventArgs e) private void OpenFileExec (object control, ExecutedRoutedEventArgs e)
{ {
@ -985,12 +986,12 @@ namespace GARbro.GUI
return; return;
if ("audio" == entry.Type) if ("audio" == entry.Type)
{ {
#region ADL #region ADL
if (AudioFileList.Count() > 0) if (AudioFileList.Count() > 0)
{ {
AudioFileList.Clear(); AudioFileList.Clear();
} }
#endregion #endregion
PlayFile(entry.Source); PlayFile(entry.Source);
return; return;
} }
@ -1074,7 +1075,7 @@ namespace GARbro.GUI
} }
} }
#region ADL_PLAYBACK #region ADL_PLAYBACK
List<Entry> AudioFileList = new List<Entry>(); List<Entry> AudioFileList = new List<Entry>();
bool isAudioLoop = false; bool isAudioLoop = false;
int CurrentAudioFileListIdx = 0; int CurrentAudioFileListIdx = 0;
@ -1147,6 +1148,26 @@ namespace GARbro.GUI
SetStatusText(string.Format("Files in {0} cannot be played.", selected)); SetStatusText(string.Format("Files in {0} cannot be played.", selected));
} }
} }
private void CanAudioNextExec(object control, CanExecuteRoutedEventArgs e)
{
e.CanExecute = (AudioFileList.Count > 1) ? true : false;
}
private void AudioNextExec(object control, ExecutedRoutedEventArgs e)
{
++CurrentAudioFileListIdx;
if (CurrentAudioFileListIdx >= AudioFileList.Count) CurrentAudioFileListIdx = 0;
PlayFile(AudioFileList[CurrentAudioFileListIdx]);
}
private void CanAudioPreviousExec(object control, CanExecuteRoutedEventArgs e)
{
e.CanExecute = (AudioFileList.Count > 1) ? true : false;
}
private void AudioPreviousExec(object control, ExecutedRoutedEventArgs e)
{
--CurrentAudioFileListIdx;
if (CurrentAudioFileListIdx < 0) CurrentAudioFileListIdx = AudioFileList.Count - 1;
PlayFile(AudioFileList[CurrentAudioFileListIdx]);
}
private void AudioLoopAllExec(object control, ExecutedRoutedEventArgs e) private void AudioLoopAllExec(object control, ExecutedRoutedEventArgs e)
{ {
isAudioLoop = true; isAudioLoop = true;
@ -1206,7 +1227,7 @@ namespace GARbro.GUI
} }
#endregion #endregion
private void PlayFile (Entry entry) private void PlayFile (Entry entry)
{ {
@ -1241,10 +1262,10 @@ namespace GARbro.GUI
AudioDevice.Play(); AudioDevice.Play();
#region ADL #region ADL
if (AudioFileList.Count == 0) if (AudioFileList.Count == 0)
AudioFileList.Add(entry); AudioFileList.Add(entry);
appPauseControl.Visibility = Visibility.Visible; appPauseAudioControl.Visibility = Visibility.Visible;
SetAppPauseControlIcon(); SetAppPauseControlIcon();
//this.app_notify_icon.ShowBalloonTip(2000, "Now playing:", entry.Name, Form.ToolTipIcon.Info); //this.app_notify_icon.ShowBalloonTip(2000, "Now playing:", entry.Name, Form.ToolTipIcon.Info);
@ -1254,7 +1275,12 @@ namespace GARbro.GUI
String.Format(guiStrings.MsgNowPlaying, entry.Name) String.Format(guiStrings.MsgNowPlaying, entry.Name)
); );
trayUpdate(String.Format(guiStrings.MsgNowPlaying, entry.Name)); trayUpdate(String.Format(guiStrings.MsgNowPlaying, entry.Name));
#endregion if (AudioFileList.Count > 1)
{
appNextAudioControl.Visibility = Visibility.Visible;
appPreviousAudioControl.Visibility = Visibility.Visible;
}
#endregion
appPlaybackControl.Visibility = Visibility.Visible; appPlaybackControl.Visibility = Visibility.Visible;
var fmt = CurrentAudio.WaveFormat; var fmt = CurrentAudio.WaveFormat;
@ -1290,7 +1316,7 @@ namespace GARbro.GUI
CurrentAudio = null; CurrentAudio = null;
appPlaybackControl.Visibility = Visibility.Collapsed; appPlaybackControl.Visibility = Visibility.Collapsed;
#region ADL #region ADL
trayUpdate(""); trayUpdate("");
if (AudioFileList.Count > 0 && AudioFileList.Count > ++CurrentAudioFileListIdx) if (AudioFileList.Count > 0 && AudioFileList.Count > ++CurrentAudioFileListIdx)
{ {
@ -1305,12 +1331,14 @@ namespace GARbro.GUI
} }
else else
{ {
appPauseControl.Visibility = Visibility.Collapsed; appPauseAudioControl.Visibility = Visibility.Collapsed;
appNextAudioControl.Visibility = Visibility.Collapsed;
appPreviousAudioControl.Visibility = Visibility.Collapsed;
AudioFileList.Clear(); AudioFileList.Clear();
trayUpdate(guiStrings.MsgRunning); trayUpdate(guiStrings.MsgRunning);
} }
} }
#endregion #endregion
} }
catch (Exception X) catch (Exception X)
@ -1749,6 +1777,11 @@ namespace GARbro.GUI
Trace.WriteLine (X.Message, "Drop event failed"); Trace.WriteLine (X.Message, "Drop event failed");
} }
} }
private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
{
}
} }
public class SortModeToBooleanConverter : IValueConverter public class SortModeToBooleanConverter : IValueConverter
@ -1770,7 +1803,7 @@ namespace GARbro.GUI
public class BooleanToCollapsedVisibilityConverter : IValueConverter public class BooleanToCollapsedVisibilityConverter : IValueConverter
{ {
#region IValueConverter Members #region IValueConverter Members
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{ {
@ -1784,7 +1817,7 @@ namespace GARbro.GUI
throw new NotImplementedException(); throw new NotImplementedException();
} }
#endregion #endregion
} }
public static class Commands public static class Commands
@ -1820,13 +1853,13 @@ namespace GARbro.GUI
public static readonly RoutedCommand TroubleShooting = new RoutedCommand(); public static readonly RoutedCommand TroubleShooting = new RoutedCommand();
public static readonly RoutedCommand Descend = new RoutedCommand(); public static readonly RoutedCommand Descend = new RoutedCommand();
public static readonly RoutedCommand Ascend = new RoutedCommand(); public static readonly RoutedCommand Ascend = new RoutedCommand();
#region ADL #region ADL
public static readonly RoutedCommand AudioPlayAll = new RoutedCommand(); public static readonly RoutedCommand AudioPlayAll = new RoutedCommand();
public static readonly RoutedCommand AudioLoopAll = new RoutedCommand(); public static readonly RoutedCommand AudioLoopAll = new RoutedCommand();
public static readonly RoutedCommand AudioStopAll = new RoutedCommand(); public static readonly RoutedCommand AudioStopAll = new RoutedCommand();
public static readonly RoutedCommand AudioPauseContinue = new RoutedCommand(); public static readonly RoutedCommand AudioPauseContinue = new RoutedCommand();
//public static readonly RoutedCommand AudioNext = new RoutedCommand(); public static readonly RoutedCommand AudioNext = new RoutedCommand();
//public static readonly RoutedCommand AudioPrevious = new RoutedCommand(); public static readonly RoutedCommand AudioPrevious = new RoutedCommand();
#endregion #endregion
} }
} }