JD2022-TU1/main/tools/framework/JD.Application.TeaBox/View/Actions/PlaybackActionHandlerBase.cs

48 lines
No EOL
1.3 KiB
C#

using JD.Audio.SoundPlayer;
using JD.Interfaces.Player;
using TeaBox;
namespace JD.Application.View.Actions
{
/// <summary>
/// Base class for an action to execute on a player.
/// </summary>
public class PlaybackActionHandlerBase : ActionHandler
{
private IPlayer ResolvePlayer(ActionContext context)
{
var provider = context.Target as IPlayerProvider ?? global::TeaBox.ObjectModel.Application.Main.Views.SelectedItem as IPlayerProvider;
return provider != null ? provider.Player : null;
}
public override bool Update(ActionContext context, ActionInfo info)
{
var player = ResolvePlayer(context);
info.Enabled = player != null;
if (player != null)
{
Update(info, player);
}
return true;
}
public override void Execute(ActionExecutionContext context)
{
var player = ResolvePlayer(context);
if (player != null)
{
Execute(player);
}
}
protected virtual void Update(ActionInfo info, IPlayer player)
{
}
protected virtual void Execute(IPlayer player)
{
}
}
}