当前位置:网站首页>Unity学习笔记 关于AVPro视频跳转功能(Seeking)的说明
Unity学习笔记 关于AVPro视频跳转功能(Seeking)的说明
2022-07-31 13:40:00 【Lawa0592】
1. Seeking功能的相关接口
通过双精度时间寻找跳转:
- Seek() ⇒ 跳转到精确的指定时间上的画面
- SeekFast() ⇒ 跳转到指定时间上最近的帧画面
- SeekWithTolerance() ⇒ 跳转到指定时间上某个范围时间内的画面(只支持macOS,ios,tvOS)
通过使用帧寻找跳转(只对具有已知恒定帧速率的媒体有效):
- SeekToFrame() ⇒ 跳转到具体某一帧的画面
- SeekToFrameRelative() ⇒ 跳转到相对于当前帧向前或向后多少帧的画面
底层接口源码如下:
/// <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);
需要注意的是,跳转的响应/行为在不同平台会有不同差异
平台 | 快速近似关键帧搜索(Fast Approximate Keyframe Seeking) | 慢速精确寻帧(Slow Accurate Frame Seeking) |
---|---|---|
Windows (WinRT / Media Foundation) | * | * |
Windows (DirectShow) | * | 取决于编解码器 |
Android (ExoPlayer) | * | * |
Android (MediaPlayer) | * | API 26 及以上 |
macOS | * | * |
iOS/iPadOS/tvOS | * | * |
WebGL | * | 视情况而变化 |
2. 跳转(Seeking)功能的实现案例
具体的实现可以参考AVPro提供的Demo(Demo_MediaPlayer场景)
下面只列出结合时间条(slider)进行视频跳转的部分:
[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);
}
参考文献
边栏推荐
- C#使用NumericUpDown控件
- ICML2022 | Fully Granular Self-Semantic Propagation for Self-Supervised Graph Representation Learning
- 六石编程学:不论是哪个功能,你觉得再没用,会用的人都离不了,所以至少要做到99%
- Install the latest pytorch gpu version
- Introduction to the PartImageNet Semantic Part Segmentation dataset
- C# List Usage List Introduction
- selenium被反爬了怎么办?
- golang-gin-优雅重启
- C#控件ListView用法
- Talk about the message display mechanism on the SAP product UI
猜你喜欢
Golang - gin - pprof - use and safety
Hard disk partition, expand disk C, no reshipment system, not heavy D dish of software full tutorial.
ECCV2022: Recursion on Transformer without adding parameters and less computation!
Solution for browser hijacking by hao360
关于MySQL主从复制的数据同步延迟问题
技能大赛训练题:登录安全加固
Edge Cloud Explained in Simple Depth | 4. Lifecycle Management
golang-gin-pprof-使用以及安全问题
PHP Serialization: eval
hyperf的启动源码分析(二)——请求如何到达控制器
随机推荐
Batch大小不一定是2的n次幂!ML资深学者最新结论
代码随想录笔记_哈希_454四数相加II
golang-gin-pprof-使用以及安全问题
百度网盘安装在c盘显示系统权限限制的解决方法
抓住金三银四的尾巴,解锁程序员面试《刷题神器》
Sliding window method to segment data
基于神经网络的多柔性梁耦合结构振动控制
全局平均池化层替代全连接层(最大池化和平均池化的区别)
TensorRT安装及使用教程「建议收藏」
基于模糊预测与扩展卡尔曼滤波的野值剔除方法
uniapp微信小程序引用标准版交易组件
计算机复试面试问题(计算机面试常见问题)
selenium被反爬了怎么办?
sqlalchemy determines whether a field of type array has at least one consistent data with an array
365-day challenge LeetCode1000 questions - Day 044 Maximum element in the layer and level traversal
4.爬虫之Scrapy框架2数据解析&配置参数&数据持久化&提高Scrapy效率
动作捕捉系统用于柔性机械臂的末端定位控制
hyperf的启动源码分析(二)——请求如何到达控制器
LeetCode·每日一题·1161.最大层内元素和·层次遍历
ADS与C#通信