Skip to content

Commit caa1d0b

Browse files
committed
updated to v2.11.11
1 parent 0d076a4 commit caa1d0b

6 files changed

Lines changed: 81 additions & 20 deletions

File tree

Assets/OxGFrame/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# CHANGELOG
22

3+
## [2.11.11] - 2024-10-15
4+
- Added SkipToPercent method in VideoBase (You can use a percentage to jump to a specific segment of the video).
5+
- Added SetPlaySpeed in VideoBase.
6+
- Added CurrentRemainingLength in MediaBase.
7+
- Fixed CurrentLength return value in MediaBase.
8+
39
## [2.11.10] - 2024-10-08
410
- Added CoreFrames.USFrame.GetActiveScene() method.
511
- Added CoreFrames.USFrame.SetActiveScene(int index) method.

Assets/OxGFrame/MediaFrame/Scripts/Runtime/Core/AudioFrame/AudioBase.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private async UniTask _InitAudio()
8888
this._audioSource.priority = this.audioType.priority;
8989
this._audioSource.outputAudioMixerGroup = this._mixerGroup;
9090
this._audioSource.loop = (this.loops == -1) ? true : false;
91-
this._mediaLength = this._currentLength = (this.audioLength > 0) ? this.audioLength : this.audioClip.length;
91+
this._mediaLength = this._currentRemainingLength = (this.audioLength > 0) ? this.audioLength : this.audioClip.length;
9292

9393
this.isPrepared = true;
9494

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

120120
if (this.IsPaused()) return;
121121

122-
if (this.CurrentLength() > 0f)
122+
if (this.CurrentRemainingLength() > 0f)
123123
{
124-
this._currentLength -= dt;
125-
if (this.CurrentLength() <= 0f)
124+
this._currentRemainingLength -= dt;
125+
if (this.CurrentRemainingLength() <= 0f)
126126
{
127127
if (this._loops >= 0)
128128
{
@@ -131,12 +131,12 @@ protected override void OnFixedUpdate(float dt = 0f)
131131
this._loops--;
132132
if (this._loops <= 0)
133133
{
134-
this._currentLength = 0;
134+
this._currentRemainingLength = 0;
135135
if (this.autoEndToStop) this.StopSelf();
136136
}
137137
else this._audioSource.Play();
138138
}
139-
this._currentLength = this.Length();
139+
this._currentRemainingLength = this.Length();
140140
}
141141
}
142142
}
@@ -219,7 +219,12 @@ public override float Length()
219219

220220
public override float CurrentLength()
221221
{
222-
return this._currentLength;
222+
return this._mediaLength - this._currentRemainingLength;
223+
}
224+
225+
public override float CurrentRemainingLength()
226+
{
227+
return this._currentRemainingLength;
223228
}
224229

225230
public override void OnRelease()

Assets/OxGFrame/MediaFrame/Scripts/Runtime/Core/AudioFrame/AudioManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ private void _Play(AudioBase audBase, int loops, float volume)
383383

384384
this.LoadAndPlay(audBase, loops, volume);
385385

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

389389
/// <summary>
@@ -532,7 +532,7 @@ private void _Pause(AudioBase audBase)
532532

533533
this.ExitAndStop(audBase, true, false);
534534

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

538538
/// <summary>

Assets/OxGFrame/MediaFrame/Scripts/Runtime/Core/Implement/MediaBase.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public async UniTask<string> GetFileText()
8787
protected bool _isPaused = false; // 是否暫停
8888
protected bool _isInit = false; // 初始標記 (表示確認初始完畢)
8989
protected float _mediaLength = 0f; // 影音長度
90-
protected float _currentLength = 0f; // 影音當前長度
90+
protected float _currentRemainingLength = 0f; // 影音當前長度
9191
protected Action _endEvent = null; // 停止播放時的事件調用
9292
public bool isPrepared { get; protected set; } = false; // 影音準備好的標記
9393
internal bool isDestroying = false; // 正在被銷毀的標記
@@ -153,6 +153,12 @@ internal void HandleFixedUpdate(float dt)
153153
/// <returns></returns>
154154
public abstract float CurrentLength();
155155

156+
/// <summary>
157+
/// 取得當前影音剩餘長度 -> Remaining time (單位: 秒)
158+
/// </summary>
159+
/// <returns></returns>
160+
public abstract float CurrentRemainingLength();
161+
156162
/// <summary>
157163
/// 設置停止播放時的事件 Callback
158164
/// </summary>
@@ -170,7 +176,7 @@ public virtual void OnRelease()
170176
this.assetName = null;
171177
this.mediaName = null;
172178
this._mediaLength = 0f;
173-
this._currentLength = 0f;
179+
this._currentRemainingLength = 0f;
174180
this._endEvent = null;
175181
}
176182

@@ -184,7 +190,7 @@ public virtual void OnRelease()
184190
/// </summary>
185191
protected virtual void ResetLength()
186192
{
187-
this._currentLength = this._mediaLength;
193+
this._currentRemainingLength = this._mediaLength;
188194
}
189195

190196
/// <summary>

Assets/OxGFrame/MediaFrame/Scripts/Runtime/Core/VideoFrame/VideoBase.cs

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private async UniTask _InitVideo()
126126
break;
127127
}
128128

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

131131
this.isPrepared = true;
132132

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

190190
if (this.IsPaused()) return;
191191

192-
if (this.CurrentLength() > 0f)
192+
if (this.CurrentRemainingLength() > 0f)
193193
{
194-
this._currentLength -= dt;
195-
if (this.CurrentLength() <= 0f)
194+
this._currentRemainingLength -= dt;
195+
if (this.CurrentRemainingLength() <= 0f)
196196
{
197197
if (this._loops >= 0)
198198
{
@@ -201,12 +201,12 @@ protected override void OnFixedUpdate(float dt = 0f)
201201
this._loops--;
202202
if (this._loops <= 0)
203203
{
204-
this._currentLength = 0;
204+
this._currentRemainingLength = 0;
205205
if (this.autoEndToStop) this.StopSelf();
206206
}
207207
else this._videoPlayer.Play();
208208
}
209-
this._currentLength = this.Length();
209+
this._currentRemainingLength = this.Length();
210210
}
211211
}
212212
}
@@ -285,7 +285,12 @@ public override float Length()
285285

286286
public override float CurrentLength()
287287
{
288-
return this._currentLength;
288+
return this._mediaLength - this._currentRemainingLength;
289+
}
290+
291+
public override float CurrentRemainingLength()
292+
{
293+
return this._currentRemainingLength;
289294
}
290295

291296
public override void OnRelease()
@@ -303,6 +308,45 @@ public override void OnRelease()
303308
this._targetCamera = null;
304309
}
305310

311+
/// <summary>
312+
/// Skip range is 0.0 to 1.0 pct
313+
/// </summary>
314+
/// <param name="pct"></param>
315+
public void SkipToPercent(float pct)
316+
{
317+
if (this._videoPlayer == null) return;
318+
319+
// Clamp pct to ensure it's between 0.0 and 1.0
320+
pct = Mathf.Clamp(pct, 0f, 1f);
321+
322+
var frame = this._videoPlayer.frameCount * pct;
323+
this._videoPlayer.frame = (long)frame;
324+
325+
// update length infos
326+
this._mediaLength = (1f * this._videoPlayer.frameCount / this._videoPlayer.playbackSpeed / this._videoPlayer.frameRate);
327+
this._currentRemainingLength = this._mediaLength - (1f * frame / this._videoPlayer.playbackSpeed / this._videoPlayer.frameRate);
328+
// offset remaining time
329+
if (this._currentRemainingLength <= 0)
330+
this._currentRemainingLength = 0.1f;
331+
}
332+
333+
/// <summary>
334+
/// Set speed range is 0.01 to float.MaxValue
335+
/// <para>Generally we recommend these rates: 0.25, 0.5, 1.0, 1.25, 1.5, 1.75, 2.0</para>
336+
/// </summary>
337+
/// <param name="speed"></param>
338+
public void SetPlaySpeed(float speed)
339+
{
340+
if (this._videoPlayer == null) return;
341+
342+
// Clamp speed to ensure it does not go below 0.1
343+
speed = Mathf.Clamp(speed, 0.01f, float.MaxValue);
344+
345+
this._videoPlayer.playbackSpeed = speed;
346+
// use skip to percent to update current length and media total length
347+
this.SkipToPercent((this._mediaLength - this._currentRemainingLength) / this._mediaLength);
348+
}
349+
306350
public VideoPlayer GetVideoPlayer()
307351
{
308352
return this._videoPlayer;

Assets/OxGFrame/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "com.michaelo.oxgframe",
33
"displayName": "OxGFrame",
44
"description": "The OxGFrame is a framework based on Unity for accelerating game development. Supports multi-platform Win, OSX, Android, iOS, WebGL.",
5-
"version": "2.11.10",
5+
"version": "2.11.11",
66
"unity": "2021.3",
77
"license": "MIT",
88
"samples": [

0 commit comments

Comments
 (0)