Skip to content

Commit

Permalink
updated to v2.11.11
Browse files Browse the repository at this point in the history
  • Loading branch information
michael811125 committed Oct 15, 2024
1 parent 0d076a4 commit caa1d0b
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 20 deletions.
6 changes: 6 additions & 0 deletions Assets/OxGFrame/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## [2.11.11] - 2024-10-15
- Added SkipToPercent method in VideoBase (You can use a percentage to jump to a specific segment of the video).
- Added SetPlaySpeed in VideoBase.
- Added CurrentRemainingLength in MediaBase.
- Fixed CurrentLength return value in MediaBase.

## [2.11.10] - 2024-10-08
- Added CoreFrames.USFrame.GetActiveScene() method.
- Added CoreFrames.USFrame.SetActiveScene(int index) method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private async UniTask _InitAudio()
this._audioSource.priority = this.audioType.priority;
this._audioSource.outputAudioMixerGroup = this._mixerGroup;
this._audioSource.loop = (this.loops == -1) ? true : false;
this._mediaLength = this._currentLength = (this.audioLength > 0) ? this.audioLength : this.audioClip.length;
this._mediaLength = this._currentRemainingLength = (this.audioLength > 0) ? this.audioLength : this.audioClip.length;

this.isPrepared = true;

Expand Down Expand Up @@ -119,10 +119,10 @@ protected override void OnFixedUpdate(float dt = 0f)

if (this.IsPaused()) return;

if (this.CurrentLength() > 0f)
if (this.CurrentRemainingLength() > 0f)
{
this._currentLength -= dt;
if (this.CurrentLength() <= 0f)
this._currentRemainingLength -= dt;
if (this.CurrentRemainingLength() <= 0f)
{
if (this._loops >= 0)
{
Expand All @@ -131,12 +131,12 @@ protected override void OnFixedUpdate(float dt = 0f)
this._loops--;
if (this._loops <= 0)
{
this._currentLength = 0;
this._currentRemainingLength = 0;
if (this.autoEndToStop) this.StopSelf();
}
else this._audioSource.Play();
}
this._currentLength = this.Length();
this._currentRemainingLength = this.Length();
}
}
}
Expand Down Expand Up @@ -219,7 +219,12 @@ public override float Length()

public override float CurrentLength()
{
return this._currentLength;
return this._mediaLength - this._currentRemainingLength;
}

public override float CurrentRemainingLength()
{
return this._currentRemainingLength;
}

public override void OnRelease()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ private void _Play(AudioBase audBase, int loops, float volume)

this.LoadAndPlay(audBase, loops, volume);

Logging.Print<Logger>(string.Format("Play Audio: {0}, Current Length: {1} (s)", audBase?.mediaName, audBase?.CurrentLength()));
Logging.Print<Logger>(string.Format("Play Audio: {0}, Current Length: {1} (s)", audBase?.mediaName, audBase?.CurrentRemainingLength()));
}

/// <summary>
Expand Down Expand Up @@ -532,7 +532,7 @@ private void _Pause(AudioBase audBase)

this.ExitAndStop(audBase, true, false);

Logging.Print<Logger>(string.Format("Pause Audio: {0}, Current Length: {1} (s)", audBase?.mediaName, audBase?.CurrentLength()));
Logging.Print<Logger>(string.Format("Pause Audio: {0}, Current Length: {1} (s)", audBase?.mediaName, audBase?.CurrentRemainingLength()));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public async UniTask<string> GetFileText()
protected bool _isPaused = false; // 是否暫停
protected bool _isInit = false; // 初始標記 (表示確認初始完畢)
protected float _mediaLength = 0f; // 影音長度
protected float _currentLength = 0f; // 影音當前長度
protected float _currentRemainingLength = 0f; // 影音當前長度
protected Action _endEvent = null; // 停止播放時的事件調用
public bool isPrepared { get; protected set; } = false; // 影音準備好的標記
internal bool isDestroying = false; // 正在被銷毀的標記
Expand Down Expand Up @@ -153,6 +153,12 @@ internal void HandleFixedUpdate(float dt)
/// <returns></returns>
public abstract float CurrentLength();

/// <summary>
/// 取得當前影音剩餘長度 -> Remaining time (單位: 秒)
/// </summary>
/// <returns></returns>
public abstract float CurrentRemainingLength();

/// <summary>
/// 設置停止播放時的事件 Callback
/// </summary>
Expand All @@ -170,7 +176,7 @@ public virtual void OnRelease()
this.assetName = null;
this.mediaName = null;
this._mediaLength = 0f;
this._currentLength = 0f;
this._currentRemainingLength = 0f;
this._endEvent = null;
}

Expand All @@ -184,7 +190,7 @@ public virtual void OnRelease()
/// </summary>
protected virtual void ResetLength()
{
this._currentLength = this._mediaLength;
this._currentRemainingLength = this._mediaLength;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private async UniTask _InitVideo()
break;
}

this._mediaLength = this._currentLength = (1f * this._videoPlayer.frameCount / this._videoPlayer.frameRate);
this._mediaLength = this._currentRemainingLength = (1f * this._videoPlayer.frameCount / this._videoPlayer.playbackSpeed / this._videoPlayer.frameRate);

this.isPrepared = true;

Expand Down Expand Up @@ -189,10 +189,10 @@ protected override void OnFixedUpdate(float dt = 0f)

if (this.IsPaused()) return;

if (this.CurrentLength() > 0f)
if (this.CurrentRemainingLength() > 0f)
{
this._currentLength -= dt;
if (this.CurrentLength() <= 0f)
this._currentRemainingLength -= dt;
if (this.CurrentRemainingLength() <= 0f)
{
if (this._loops >= 0)
{
Expand All @@ -201,12 +201,12 @@ protected override void OnFixedUpdate(float dt = 0f)
this._loops--;
if (this._loops <= 0)
{
this._currentLength = 0;
this._currentRemainingLength = 0;
if (this.autoEndToStop) this.StopSelf();
}
else this._videoPlayer.Play();
}
this._currentLength = this.Length();
this._currentRemainingLength = this.Length();
}
}
}
Expand Down Expand Up @@ -285,7 +285,12 @@ public override float Length()

public override float CurrentLength()
{
return this._currentLength;
return this._mediaLength - this._currentRemainingLength;
}

public override float CurrentRemainingLength()
{
return this._currentRemainingLength;
}

public override void OnRelease()
Expand All @@ -303,6 +308,45 @@ public override void OnRelease()
this._targetCamera = null;
}

/// <summary>
/// Skip range is 0.0 to 1.0 pct
/// </summary>
/// <param name="pct"></param>
public void SkipToPercent(float pct)
{
if (this._videoPlayer == null) return;

// Clamp pct to ensure it's between 0.0 and 1.0
pct = Mathf.Clamp(pct, 0f, 1f);

var frame = this._videoPlayer.frameCount * pct;
this._videoPlayer.frame = (long)frame;

// update length infos
this._mediaLength = (1f * this._videoPlayer.frameCount / this._videoPlayer.playbackSpeed / this._videoPlayer.frameRate);
this._currentRemainingLength = this._mediaLength - (1f * frame / this._videoPlayer.playbackSpeed / this._videoPlayer.frameRate);
// offset remaining time
if (this._currentRemainingLength <= 0)
this._currentRemainingLength = 0.1f;
}

/// <summary>
/// Set speed range is 0.01 to float.MaxValue
/// <para>Generally we recommend these rates: 0.25, 0.5, 1.0, 1.25, 1.5, 1.75, 2.0</para>
/// </summary>
/// <param name="speed"></param>
public void SetPlaySpeed(float speed)
{
if (this._videoPlayer == null) return;

// Clamp speed to ensure it does not go below 0.1
speed = Mathf.Clamp(speed, 0.01f, float.MaxValue);

this._videoPlayer.playbackSpeed = speed;
// use skip to percent to update current length and media total length
this.SkipToPercent((this._mediaLength - this._currentRemainingLength) / this._mediaLength);
}

public VideoPlayer GetVideoPlayer()
{
return this._videoPlayer;
Expand Down
2 changes: 1 addition & 1 deletion Assets/OxGFrame/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "com.michaelo.oxgframe",
"displayName": "OxGFrame",
"description": "The OxGFrame is a framework based on Unity for accelerating game development. Supports multi-platform Win, OSX, Android, iOS, WebGL.",
"version": "2.11.10",
"version": "2.11.11",
"unity": "2021.3",
"license": "MIT",
"samples": [
Expand Down

0 comments on commit caa1d0b

Please sign in to comment.