当前位置:网站首页>Unity study notes Description of AVPro video jump function (Seeking)
Unity study notes Description of AVPro video jump function (Seeking)
2022-07-31 13:45:00 【Lawa0592】
1. SeekingFunction related interface
Find jumps by double-precision time:
- Seek() ⇒ Jump to the screen at the exact specified time
- SeekFast() ⇒ Jump to the most recent frame at the specified time
- SeekWithTolerance() ⇒ Jump to the screen within a certain range at the specified time(只支持macOS,ios,tvOS)
Find jumps by using frames(Only valid for media with a known constant frame rate):
- SeekToFrame() ⇒ Jump to a specific frame of the picture
- SeekToFrameRelative() ⇒ Jump to the frame how many frames forward or backward relative to the current frame
The source code of the underlying interface is as follows:
/// <summary>
/// The time in seconds seeked will be to the exact time
/// This can take a long time is the keyframes are far apart
/// Some platforms don't support this and instead seek to the closest keyframe
/// </summary>
void Seek(double time);
/// <summary>
/// The time in seconds seeked will be to the closest keyframe
/// </summary>
void SeekFast(double time);
/// <summary>
/// The time in seconds seeked to will be within the range [time-timeDeltaBefore, time+timeDeltaAfter] for efficiency.
/// Only supported on macOS, iOS and tvOS.
/// Other platforms will automatically pass through to Seek()
/// </summary>
void SeekWithTolerance(double time, double timeDeltaBefore, double timeDeltaAfter);
/// <summary>
/// Seek to a specific frame, range is [0, GetMaxFrameNumber()]
/// NOTE: For best results the video should be encoded as keyframes only
/// and have no audio track, or an audio track with the same length as the video track
/// </summary>
void SeekToFrame(int frame, float overrideFrameRate = 0f);
/// <summary>
/// Seek forwards or backwards relative to the current frame
/// NOTE: For best results the video should be encoded as keyframes only
/// and have no audio track, or an audio track with the same length as the video track
/// </summary>
void SeekToFrameRelative(int frameOffset, float overrideFrameRate = 0f);
需要注意的是,Jump response/Behavior varies on different platforms
| 平台 | Fast approximate keyframe search(Fast Approximate Keyframe Seeking) | Accurate framing at slow speed(Slow Accurate Frame Seeking) |
|---|---|---|
| Windows (WinRT / Media Foundation) | * | * |
| Windows (DirectShow) | * | Depends on the codec |
| Android (ExoPlayer) | * | * |
| Android (MediaPlayer) | * | API 26 及以上 |
| macOS | * | * |
| iOS/iPadOS/tvOS | * | * |
| WebGL | * | Varies depending on the situation |
2. 跳转(Seeking)Example of the implementation of the function
具体的实现可以参考AVPro提供的Demo(Demo_MediaPlayer场景)
Only the combined time bar is listed below(slider)The part where video jumps are made:
[Header("UI Components")]
[SerializeField] Slider _sliderTime = null;
void Start()
{
CreateTimelineDragEvents();
}
private void CreateTimelineDragEvents()
{
EventTrigger trigger = _sliderTime.gameObject.GetComponent<EventTrigger>();
if (trigger != null)
{
EventTrigger.Entry entry = new EventTrigger.Entry();
entry.eventID = EventTriggerType.PointerDown;
entry.callback.AddListener((data) => {
OnTimeSliderBeginDrag(); });
trigger.triggers.Add(entry);
entry = new EventTrigger.Entry();
entry.eventID = EventTriggerType.Drag;
entry.callback.AddListener((data) => {
OnTimeSliderDrag(); });
trigger.triggers.Add(entry);
entry = new EventTrigger.Entry();
entry.eventID = EventTriggerType.PointerUp;
entry.callback.AddListener((data) => {
OnTimeSliderEndDrag(); });
trigger.triggers.Add(entry);
entry = new EventTrigger.Entry();
entry.eventID = EventTriggerType.PointerEnter;
entry.callback.AddListener((data) => {
OnTimelineBeginHover((PointerEventData)data); });
trigger.triggers.Add(entry);
entry = new EventTrigger.Entry();
entry.eventID = EventTriggerType.PointerExit;
entry.callback.AddListener((data) => {
OnTimelineEndHover((PointerEventData)data); });
trigger.triggers.Add(entry);
}
}
private bool _wasPlayingBeforeTimelineDrag;
private void OnTimeSliderBeginDrag()
{
if (_mediaPlayer && _mediaPlayer.Control != null)
{
_wasPlayingBeforeTimelineDrag = _mediaPlayer.Control.IsPlaying();
if (_wasPlayingBeforeTimelineDrag)
{
_mediaPlayer.Pause();
}
OnTimeSliderDrag();
}
}
private void OnTimeSliderDrag()
{
if (_mediaPlayer && _mediaPlayer.Control != null)
{
TimeRange timelineRange = GetTimelineRange();
double time = timelineRange.startTime + (_sliderTime.value * timelineRange.duration);
_mediaPlayer.Control.Seek(time);
_isHoveringOverTimeline = true;
}
}
private void OnTimeSliderEndDrag()
{
if (_mediaPlayer && _mediaPlayer.Control != null)
{
if (_wasPlayingBeforeTimelineDrag)
{
_mediaPlayer.Play();
_wasPlayingBeforeTimelineDrag = false;
}
}
}
private bool _isHoveringOverTimeline;
private void OnTimelineBeginHover(PointerEventData eventData)
{
if (eventData.pointerCurrentRaycast.gameObject != null)
{
_isHoveringOverTimeline = true;
_sliderTime.transform.localScale = new Vector3(1f, 2.5f, 1f);
}
}
private void OnTimelineEndHover(PointerEventData eventData)
{
_isHoveringOverTimeline = false;
_sliderTime.transform.localScale = new Vector3(1f, 1f, 1f);
}
参考文献
边栏推荐
猜你喜欢
随机推荐
Six Stones Programming: No matter which function you think is useless, people who can use it will not be able to leave, so at least 99%
【redis】发布和订阅消息
网络层重点协议——IP协议
LeetCode·每日一题·1161.最大层内元素和·层次遍历
代码随想录笔记_哈希_454四数相加II
清除浮动的四种方式及其原理理解
C#控件StatusStrip使用
深度剖析 Apache EventMesh 云原生分布式事件驱动架构
LeetCode旋转数组
Spark Learning: Add Custom Optimization Rules for Spark Sql
go使用makefile脚本编译应用
ASM module in SAP Ecommerce Cloud Spartacus UI and Accelerator UI
计算机复试面试问题(计算机面试常见问题)
csdn发文助手问题
C# control ListView usage
基于高阶微分器的无模型滑模控制器及其在自动电压调节器中的应用
ADS communicate with c #
报错:npm ERR code EPERM
C# control StatusStrip use
「面经分享」西北大学 | 字节 生活服务 | 一面二面三面 HR 面









