添加了教育平台
This commit is contained in:
@@ -18,7 +18,7 @@ public partial class DataPlayer : Node
|
||||
public int CurrentFrame
|
||||
{
|
||||
get => _currentFrame;
|
||||
set => _currentFrame = Math.Clamp(value, 0, Values?.Length ?? 0);
|
||||
set => _currentFrame = Math.Clamp(value, 0, Values?.Length-1 ?? 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -39,6 +39,12 @@ public partial class DataPlayer : Node
|
||||
/// </summary>
|
||||
[Signal]
|
||||
public delegate void OnPlayEventHandler();
|
||||
|
||||
/// <summary>
|
||||
/// 停止播放回调
|
||||
/// </summary>
|
||||
[Signal]
|
||||
public delegate void OnStopEventHandler();
|
||||
|
||||
/// <summary>
|
||||
/// 暂停回调
|
||||
@@ -96,6 +102,7 @@ public partial class DataPlayer : Node
|
||||
public override void _Ready()
|
||||
{
|
||||
timer.Elapsed += Play;
|
||||
EmitSignal(nameof(OnStop));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -140,6 +147,7 @@ public partial class DataPlayer : Node
|
||||
if (!IsPlaying) return false;
|
||||
timer.Stop();
|
||||
IsPlaying = IsPaused = false;
|
||||
EmitSignal(nameof(OnStop));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -158,16 +166,27 @@ public partial class DataPlayer : Node
|
||||
/// 继续播放或暂停播放
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool PlayOrPause()
|
||||
public void PlayOrPause()
|
||||
{
|
||||
if (!IsPlaying) return false;
|
||||
IsPaused = !IsPaused;
|
||||
return true;
|
||||
PlayOrPause(!IsPaused);
|
||||
}
|
||||
|
||||
public void PlayOrPause(bool play)
|
||||
{
|
||||
IsPaused = !play;
|
||||
EmitSignal(nameof(OnPlayOrPause), play);
|
||||
}
|
||||
//设置标准化播放时间(0-1进度)
|
||||
public void SetNormalizeTime(float normalizeTime)
|
||||
{
|
||||
CurrentFrame = (int)(Values.Length * normalizeTime);
|
||||
Process(CurrentFrame);
|
||||
}
|
||||
|
||||
public void SetNormalizeTimeThen(float normalizeTime, bool play)
|
||||
{
|
||||
SetNormalizeTime(normalizeTime);
|
||||
PlayOrPause(play);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
@@ -185,16 +204,23 @@ public partial class DataPlayer : Node
|
||||
{
|
||||
//等待返回主线程
|
||||
await UniTask.SwitchToSynchronizationContext(BITApp.SynchronizationContext);
|
||||
//if (IsPaused) return;
|
||||
|
||||
if (IsPaused) return;
|
||||
|
||||
//如果超过了播放长度,停止播放
|
||||
if (CurrentFrame >= Values?.Length)
|
||||
if (CurrentFrame >= Values?.Length-1)
|
||||
{
|
||||
Stop();
|
||||
return;
|
||||
}
|
||||
|
||||
EmitSignal(nameof(OnPlay));
|
||||
Process(CurrentFrame++);
|
||||
}
|
||||
|
||||
private void Process(int currentFrame)
|
||||
{
|
||||
//获取当前播放信息
|
||||
var current = Values?[CurrentFrame++];
|
||||
var current = Values?[currentFrame];
|
||||
var currentNormalizeTime = (float)CurrentFrame / Values!.Length;
|
||||
var currentTime = new DateTime().AddSeconds((float)CurrentFrame / frameRate);
|
||||
|
||||
|
Reference in New Issue
Block a user