(MainWindow) 1. Add pause functionality 2. playback for multiple-selected files.

This commit is contained in:
andylinpersonal 2018-02-10 00:46:15 +08:00
parent aa72c6f8b6
commit 44a90b3fed
4 changed files with 430 additions and 2 deletions

View File

@ -109,6 +109,23 @@
<MenuItem Header="{x:Static s:guiStrings.CtxMenuConvert}" InputGestureText="F6"
Visibility="{Binding Path=IsEnabled, RelativeSource={RelativeSource Self}, Mode=OneWay, Converter={StaticResource booleanToCollapsedVisibilityConverter}}"
Command="{x:Static local:Commands.ConvertMedia}" />
<!-- ADL Play All or Stop All-->
<Separator/>
<MenuItem Header="{x:Static s:guiStrings.CtxMenuAudioLoopAll}" InputGestureText=""
Visibility="{Binding Path=IsEnabled, RelativeSource={RelativeSource Self}, Mode=OneWay, Converter={StaticResource booleanToCollapsedVisibilityConverter}}"
Command="{x:Static local:Commands.AudioLoopAll}" />
<MenuItem Header="{x:Static s:guiStrings.CtxMenuAudioPlayAll}" InputGestureText=""
Visibility="{Binding Path=IsEnabled, RelativeSource={RelativeSource Self}, Mode=OneWay, Converter={StaticResource booleanToCollapsedVisibilityConverter}}"
Command="{x:Static local:Commands.AudioPlayAll}" />
<!-- Following items are replaced with statusbar item
<MenuItem Header="{x:Static s:guiStrings.CtxMenuAudioStopAll}" InputGestureText=""
Visibility="{Binding Path=IsEnabled, RelativeSource={RelativeSource Self}, Mode=OneWay, Converter={StaticResource booleanToCollapsedVisibilityConverter}}"
Command="{x:Static local:Commands.AudioStopAll}" />
<MenuItem Header="{x:Static s:guiStrings.CtxMenuAudioPauseContinue}" InputGestureText=""
Visibility="{Binding Path=IsEnabled, RelativeSource={RelativeSource Self}, Mode=OneWay, Converter={StaticResource booleanToCollapsedVisibilityConverter}}"
Command="{x:Static local:Commands.AudioPauseContinue}" />
-->
</ContextMenu>
</Window.Resources>
@ -255,6 +272,49 @@
<TextBlock x:Name="appStatusText"/>
</StatusBarItem>
<Separator Width="1"/>
<!-- ADL -->
<!-- TODO
<StatusBarItem x:Name="appNextControl" Visibility="Visible">
<Button x:Name="btn_appPauseControl" Width="18" Height="18"
HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
Command="{x:Static local:Commands.AudioPauseContinue}">
</Button>
</StatusBarItem>
<StatusBarItem x:Name="appPreviousControl" Visibility="Visible">
<Button x:Name="btn_appPauseControl" Width="18" Height="18"
HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
Command="{x:Static local:Commands.AudioPauseContinue}">
</Button>
</StatusBarItem>
-->
<StatusBarItem x:Name="appPauseControl" Visibility="Collapsed">
<Button x:Name="btn_appPauseControl" Width="18" Height="18"
HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
Command="{x:Static local:Commands.AudioPauseContinue}">
<!-- click to pause
<Path Stroke="Black" StrokeThickness="3">
<Path.Data>
<PathGeometry>
<PathFigure StartPoint="2,0">
<LineSegment Point="2,8" />
</PathFigure>
<PathFigure StartPoint="8,0">
<LineSegment Point="8,8" />
</PathFigure>
</PathGeometry>
</Path.Data>
</Path>-->
<!-- Click to continue
<Polygon Stroke="Black" Stretch="None" Fill="Black" Points="1,1 1,9 9,5"/>-->
</Button>
</StatusBarItem>
<StatusBarItem x:Name="appPlaybackControl" Visibility="Collapsed">
<Button Width="18" Height="18"
HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
@ -424,5 +484,11 @@
<CommandBinding Command="{x:Static local:Commands.Descend}" Executed="DescendExec" CanExecute="CanExecuteAlways"/>
<CommandBinding Command="{x:Static local:Commands.Ascend}" Executed="AscendExec" CanExecute="CanExecuteAlways"/>
<CommandBinding Command="{x:Static local:Commands.Exit}" Executed="ExitExec" CanExecute="CanExecuteAlways"/>
<!--ADL-->
<CommandBinding Command="{x:Static local:Commands.AudioLoopAll}" Executed="AudioLoopAllExec" CanExecute="CanAudioLoopAllExec"/>
<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.AudioPauseContinue}" Executed="AudioPauseContinueExec" CanExecute="CanAudioPauseContinueExec"/>
</Window.CommandBindings>
</Window>

View File

@ -45,6 +45,12 @@ using Rnd.Windows;
using Microsoft.Win32;
using NAudio.Wave;
#region ADL
using Hardcodet.Wpf.TaskbarNotification;
using System.Drawing;
using Form = System.Windows.Forms;
#endregion
namespace GARbro.GUI
{
/// <summary>
@ -58,8 +64,47 @@ namespace GARbro.GUI
const StringComparison StringIgnoreCase = StringComparison.CurrentCultureIgnoreCase;
#region ADL
Icon app_icon = new Icon(Application.GetResourceStream(new Uri("pack://application:,,,/images/sample.ico")).Stream);
TaskbarIcon tray = new TaskbarIcon();
Form.Timer hide_timer = null;
private int counter = 0;
private void hide_timer_Tick(object sender, EventArgs e)
{
counter--;
if (counter == 0)
{
hide_timer.Stop();
tray.HideBalloonTip();
}
}
/// <summary>
/// Show a balloon tip in tray icon by given timeout.
/// </summary>
/// <param name="timeout">in seconds</param>
/// <param name="title"></param>
/// <param name="message"></param>
private void trayShowBalloonTip(int timeout, string title, string message)
{
if (timeout > 0)
counter = timeout;
tray.ShowBalloonTip(title, message, app_icon, true);
hide_timer = new Form.Timer();
hide_timer.Interval = 1000; //milliseconds
hide_timer.Tick += hide_timer_Tick;
hide_timer.Start();
}
private void trayUpdate(string msg)
{
tray.ToolTipText = msg;
}
#endregion
public MainWindow()
{
m_app = Application.Current as App;
InitializeComponent();
if (this.Top < 0) this.Top = 0;
@ -83,6 +128,51 @@ namespace GARbro.GUI
}
};
pathLine.EnterKeyDown += acb_OnKeyDown;
#region ADL
var ico = new Icon(Application.GetResourceStream(new Uri("pack://application:,,,/images/sample.ico")).Stream);
tray.Icon = app_icon;
tray.ToolTipText = guiStrings.MsgRunning;
// Init member
{
m_whiterect = new System.Windows.Shapes.Rectangle();
m_whiterect.Stretch = System.Windows.Media.Stretch.Fill;
m_whiterect.Fill = System.Windows.Media.Brushes.Black;
m_whiterect.Width = btn_appPauseControl.Width;
m_whiterect.Height = btn_appPauseControl.Width;
}
{
m_btnContinue_state_continue = new System.Windows.Shapes.Polygon();
m_btnContinue_state_continue.Stroke = System.Windows.Media.Brushes.Black;
m_btnContinue_state_continue.Stretch = System.Windows.Media.Stretch.None;
m_btnContinue_state_continue.Fill = System.Windows.Media.Brushes.Black;
m_btnContinue_state_continue.Points.Add(new System.Windows.Point(1, 1));
m_btnContinue_state_continue.Points.Add(new System.Windows.Point(1, 9));
m_btnContinue_state_continue.Points.Add(new System.Windows.Point(9, 5));
}
{
m_btnContinue_state_pause = new System.Windows.Shapes.Path();
m_btnContinue_state_pause.Stroke = System.Windows.Media.Brushes.Black;
m_btnContinue_state_pause.StrokeThickness = 3;
System.Windows.Media.PathGeometry pathGeometry = new System.Windows.Media.PathGeometry();
System.Windows.Media.PathFigure line0 = new System.Windows.Media.PathFigure();
System.Windows.Media.PathFigure line1 = new System.Windows.Media.PathFigure();
System.Windows.Media.LineSegment segment0 = new System.Windows.Media.LineSegment();
System.Windows.Media.LineSegment segment1 = new System.Windows.Media.LineSegment();
line0.StartPoint = new System.Windows.Point(2.0, 0.0);
line1.StartPoint = new System.Windows.Point(8.0, 0.0);
segment0.Point = new System.Windows.Point(2.0, 8.0);
segment1.Point = new System.Windows.Point(8.0, 8.0);
line0.Segments.Add(segment0);
line1.Segments.Add(segment1);
pathGeometry.Figures.Add(line0);
pathGeometry.Figures.Add(line1);
m_btnContinue_state_pause.Data = pathGeometry;
}
#endregion
}
void WindowLoaded (object sender, RoutedEventArgs e)
@ -895,7 +985,13 @@ namespace GARbro.GUI
return;
if ("audio" == entry.Type)
{
PlayFile (entry.Source);
#region ADL
if (AudioFileList.Count() > 0)
{
AudioFileList.Clear();
}
#endregion
PlayFile(entry.Source);
return;
}
OpenDirectoryEntry (ViewModel, entry);
@ -978,6 +1074,140 @@ namespace GARbro.GUI
}
}
#region ADL_PLAYBACK
List<Entry> AudioFileList = new List<Entry>();
bool isAudioLoop = false;
int CurrentAudioFileListIdx = 0;
/*
private T[] InitArray<T>(int count) where T : new()
{
T[] array = new T[count];
for (int i = 0; i < count; i++)
array[i] = new T();
return array;
}
*/
System.Windows.Shapes.Rectangle m_whiterect = null;
System.Windows.Shapes.Polygon m_btnContinue_state_continue = null;
System.Windows.Shapes.Path m_btnContinue_state_pause = null;
private void SetAppPauseControlIcon()
{
btn_appPauseControl.Content = m_whiterect;
if (AudioDevice.PlaybackState == PlaybackState.Paused)
{
btn_appPauseControl.Content = m_btnContinue_state_continue;
}
else if (AudioDevice.PlaybackState == PlaybackState.Playing)
{
btn_appPauseControl.Content = m_btnContinue_state_pause;
}
}
private void AudioPlayAllHelper(object control, ExecutedRoutedEventArgs e)
{
List<Entry> rawfilelist = null;
bool isRegionSelected = (CurrentDirectory.SelectedItems.Count > 0);
if (isRegionSelected)
{
rawfilelist = new List<Entry>(CurrentDirectory.SelectedItems.Count);
foreach (var it in CurrentDirectory.SelectedItems)
{
rawfilelist.Add(((EntryViewModel)(it)).Source);
}
}
else
{
rawfilelist = VFS.GetFiles().ToList();
}
AudioFileList.Clear();
AudioFileList.Capacity = rawfilelist.Count();
CurrentAudioFileListIdx = 0;
foreach (var entry in rawfilelist)
{
if (entry.Type == "audio")
{
AudioFileList.Add(entry);
}
}
if (AudioFileList.Count() > 0)
{
PlayFile(AudioFileList[0]);
}
else
{
string selected = isRegionSelected ? "selected items" : "current directory";
SetStatusText(string.Format("Files in {0} cannot be played.", selected));
}
}
private void AudioLoopAllExec(object control, ExecutedRoutedEventArgs e)
{
isAudioLoop = true;
AudioPlayAllHelper(control, e);
}
private void CanAudioLoopAllExec(object control, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
}
private void AudioPlayAllExec(object control, ExecutedRoutedEventArgs e)
{
isAudioLoop = false;
AudioPlayAllHelper(control, e);
}
private void CanAudioPlayAllExec(object control, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
}
private void AudioStopAllExec(object control, ExecutedRoutedEventArgs e)
{
if (AudioFileList.Count > 0)
{
AudioFileList.Clear();
}
AudioDevice.Stop();
}
private void CanAudioStopAllExec(object control, CanExecuteRoutedEventArgs e)
{
isAudioLoop = false;
e.CanExecute = (AudioDevice != null && AudioDevice.PlaybackState != PlaybackState.Stopped);
}
private void AudioPauseContinueExec(object control, ExecutedRoutedEventArgs e)
{
if (AudioDevice != null)
{
if (AudioDevice.PlaybackState == PlaybackState.Paused)
{
trayUpdate(String.Format(guiStrings.MsgNowPlaying, AudioFileList[CurrentAudioFileListIdx].Name));
AudioDevice.Play();
}
else if (AudioDevice.PlaybackState == PlaybackState.Playing)
{
trayUpdate(String.Format(guiStrings.MsgPaused, AudioFileList[CurrentAudioFileListIdx].Name));
AudioDevice.Pause();
}
SetAppPauseControlIcon();
}
}
private void CanAudioPauseContinueExec(object control, CanExecuteRoutedEventArgs e)
{
if ((AudioDevice != null) && (AudioDevice.PlaybackState != PlaybackState.Stopped))
{
e.CanExecute = true;
}
else e.CanExecute = false;
}
#endregion
private void PlayFile (Entry entry)
{
IBinaryStream input = null;
@ -1008,7 +1238,24 @@ namespace GARbro.GUI
else
AudioDevice.Init (CurrentAudio);
AudioDevice.PlaybackStopped += OnPlaybackStopped;
AudioDevice.Play();
#region ADL
if (AudioFileList.Count == 0)
AudioFileList.Add(entry);
appPauseControl.Visibility = Visibility.Visible;
SetAppPauseControlIcon();
//this.app_notify_icon.ShowBalloonTip(2000, "Now playing:", entry.Name, Form.ToolTipIcon.Info);
trayShowBalloonTip(
4,
guiStrings.MsgNowPlaying.Replace("{0}", ""),
String.Format(guiStrings.MsgNowPlaying, entry.Name)
);
trayUpdate(String.Format(guiStrings.MsgNowPlaying, entry.Name));
#endregion
appPlaybackControl.Visibility = Visibility.Visible;
var fmt = CurrentAudio.WaveFormat;
SetResourceText (string.Format (guiStrings.MsgPlaying, entry.Name,
@ -1042,6 +1289,29 @@ namespace GARbro.GUI
SetResourceText ("");
CurrentAudio = null;
appPlaybackControl.Visibility = Visibility.Collapsed;
#region ADL
trayUpdate("");
if (AudioFileList.Count > 0 && AudioFileList.Count > ++CurrentAudioFileListIdx)
{
PlayFile(AudioFileList[CurrentAudioFileListIdx]);
}
else
{
CurrentAudioFileListIdx = 0;
if (isAudioLoop && AudioFileList.Count > 0)
{
PlayFile(AudioFileList[CurrentAudioFileListIdx]);
}
else
{
appPauseControl.Visibility = Visibility.Collapsed;
AudioFileList.Clear();
trayUpdate(guiStrings.MsgRunning);
}
}
#endregion
}
catch (Exception X)
{
@ -1550,5 +1820,13 @@ namespace GARbro.GUI
public static readonly RoutedCommand TroubleShooting = new RoutedCommand();
public static readonly RoutedCommand Descend = new RoutedCommand();
public static readonly RoutedCommand Ascend = new RoutedCommand();
#region ADL
public static readonly RoutedCommand AudioPlayAll = new RoutedCommand();
public static readonly RoutedCommand AudioLoopAll = new RoutedCommand();
public static readonly RoutedCommand AudioStopAll = new RoutedCommand();
public static readonly RoutedCommand AudioPauseContinue = new RoutedCommand();
//public static readonly RoutedCommand AudioNext = new RoutedCommand();
//public static readonly RoutedCommand AudioPrevious = new RoutedCommand();
#endregion
}
}

View File

@ -19,7 +19,7 @@ namespace GARbro.GUI.Strings {
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
public class guiStrings {
@ -159,6 +159,42 @@ namespace GARbro.GUI.Strings {
}
}
/// <summary>
/// Looks up a localized string similar to Looping....
/// </summary>
public static string CtxMenuAudioLoopAll {
get {
return ResourceManager.GetString("CtxMenuAudioLoopAll", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Continue / Pause.
/// </summary>
public static string CtxMenuAudioPauseContinue {
get {
return ResourceManager.GetString("CtxMenuAudioPauseContinue", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Playing....
/// </summary>
public static string CtxMenuAudioPlayAll {
get {
return ResourceManager.GetString("CtxMenuAudioPlayAll", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Stop playing....
/// </summary>
public static string CtxMenuAudioStopAll {
get {
return ResourceManager.GetString("CtxMenuAudioStopAll", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to _Close.
/// </summary>
@ -834,6 +870,15 @@ namespace GARbro.GUI.Strings {
}
}
/// <summary>
/// Looks up a localized string similar to Now Playing: {0}.
/// </summary>
public static string MsgNowPlaying {
get {
return ResourceManager.GetString("MsgNowPlaying", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to File {0}
///already exists.
@ -846,6 +891,15 @@ namespace GARbro.GUI.Strings {
}
}
/// <summary>
/// Looks up a localized string similar to Paused: {0}.
/// </summary>
public static string MsgPaused {
get {
return ResourceManager.GetString("MsgPaused", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Playing {0} / {3} / {2}bps / {1}Hz.
/// </summary>
@ -864,6 +918,15 @@ namespace GARbro.GUI.Strings {
}
}
/// <summary>
/// Looks up a localized string similar to GARBro is running....
/// </summary>
public static string MsgRunning {
get {
return ResourceManager.GetString("MsgRunning", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0} file added to selection.
/// </summary>

View File

@ -545,4 +545,25 @@ Overwrite?</value>
<data name="TextPreferences" xml:space="preserve">
<value>Preferences</value>
</data>
<data name="CtxMenuAudioLoopAll" xml:space="preserve">
<value>Looping...</value>
</data>
<data name="CtxMenuAudioPauseContinue" xml:space="preserve">
<value>Continue / Pause</value>
</data>
<data name="CtxMenuAudioPlayAll" xml:space="preserve">
<value>Playing...</value>
</data>
<data name="CtxMenuAudioStopAll" xml:space="preserve">
<value>Stop playing...</value>
</data>
<data name="MsgNowPlaying" xml:space="preserve">
<value>Now Playing: {0}</value>
</data>
<data name="MsgPaused" xml:space="preserve">
<value>Paused: {0}</value>
</data>
<data name="MsgRunning" xml:space="preserve">
<value>GARBro is running...</value>
</data>
</root>