当前位置:网站首页>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);
}
参考文献
边栏推荐
- 爱可可AI前沿推介(7.31)
- mysql8, starttime的下一个值作为endtime的上一个值?
- Invalid bound statement (not found)出现的原因和解决方法
- C# control ListView usage
- LeetCode只出现一次的数字
- C# Get network card information NetworkInterface IPInterfaceProperties
- golang-gin-pprof-使用以及安全问题
- C# control StatusStrip use
- Shell脚本经典案例:探测批量主机是否存活
- Spark Learning: Add Custom Optimization Rules for Spark Sql
猜你喜欢
Spark Learning: Add Custom Optimization Rules for Spark Sql
20.nn.Module
【蓝桥杯选拔赛真题46】Scratch磁铁游戏 少儿编程scratch蓝桥杯选拔赛真题讲解
How to quickly split and merge cell data in Excel
新款现代帕里斯帝预售开启,安全、舒适一个不落
networkx绘制度分布
C# Get network card information NetworkInterface IPInterfaceProperties
技能大赛训练题:登录安全加固
C# control ToolStripProgressBar usage
关于MySQL主从复制的数据同步延迟问题
随机推荐
IDEA如何运行web程序
百度网盘安装在c盘显示系统权限限制的解决方法
How to quickly split and merge cell data in Excel
IDEA找不到Database解决方法
新款现代帕里斯帝预售开启,安全、舒适一个不落
JSP中如何借助response对象实现页面跳转呢?
LeetCode·每日一题·1161.最大层内元素和·层次遍历
MATLAB | 我也做了一套绘图配色可视化模板
IDEA can't find the Database solution
基于改进YOLOv5的轻量化航空目标检测方法
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%
使用CompletableFuture进行异步处理业务
拥塞控制,CDN,端到端
PartImageNet物体部件分割(Semantic Part Segmentation)数据集介绍
uniapp微信小程序引用标准版交易组件
Even if the image is missing in a large area, it can also be repaired realistically. The new model CM-GAN takes into account the global structure and texture details
DELL SC compellent 康贝存储系统怎么抓取配置信息
Grab the tail of gold, silver and silver, unlock the programmer interview "Artifact of Brushing Questions"
Use of C# Assembly
SAP e-commerce cloud Spartacus SSR Optimization Engine execution sequence of several timeouts