- 集成 ffmpeg-kit-full-gpl 6.0.3(arm64),用 libx264 重编码修复 .h264 缺 SPS/PPS 导致的播放卡死 - 新增 VideoDownloadPlayService/VideoCacheManager,.mp4 直下直播、.h264 下载后转 mp4 缓存,转码完成后删除临时 .h264 - FFmpegKitBridge 走主线程 JNI 调用规避 IL2CPP 后台线程 FindClass 不稳定 - 视频列表按缓存状态显示 下载/播放 按钮,下载中亮色条显示百分比;播放面板原下载按钮改为保存到相册
122 lines
4.6 KiB
C#
122 lines
4.6 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using Kill.Network;
|
|
using Kill.Managers;
|
|
namespace Kill.UI.Pages
|
|
{
|
|
public class VideoUIItem : MonoBehaviour
|
|
{
|
|
public Text timeText;
|
|
public Image videoImage;
|
|
public Text data;
|
|
/// <summary>视频项:未下载时显示下载按钮(prefab 内挂载)</summary>
|
|
public Button downloadButton;
|
|
/// <summary>视频项:已下载时显示播放按钮(prefab 内挂载)</summary>
|
|
public Button playButton;
|
|
/// <summary>下载进度条底色(显示/隐藏用)</summary>
|
|
public Image loadingImage;
|
|
/// <summary>亮色进度条(loadingImage 的子物体,Image type=Filled,进度填充到它身上)</summary>
|
|
public Image fillLoadingImage;
|
|
public string videoUrl;
|
|
bool isVideo = false;
|
|
|
|
private Image FillBar => fillLoadingImage != null ? fillLoadingImage : loadingImage;
|
|
|
|
/// <summary>显示/隐藏下载进度条,开始时归零;下载中隐藏 下载/播放 按钮,完成后由 RefreshButtons 恢复</summary>
|
|
public void ShowDownloading(bool show)
|
|
{
|
|
if (loadingImage != null) loadingImage.gameObject.SetActive(show);
|
|
var bar = FillBar;
|
|
if (show && bar != null) bar.fillAmount = 0f;
|
|
// 下载期间收起 下载/播放 按钮,只留进度条
|
|
if (downloadButton != null) downloadButton.gameObject.SetActive(false);
|
|
if (playButton != null) playButton.gameObject.SetActive(false);
|
|
}
|
|
|
|
/// <summary>用下载进度刷新亮色条 fillAmount(0~1),并在完成时隐藏底色</summary>
|
|
public void UpdateDownloadProgress(bool done, Kill.Network.DownloadProgress progress)
|
|
{
|
|
if (done)
|
|
{
|
|
if (loadingImage != null) loadingImage.gameObject.SetActive(false);
|
|
return;
|
|
}
|
|
var bar = FillBar;
|
|
if (bar == null) return;
|
|
float pct = progress != null ? progress.ProgressPercentage : 0f;
|
|
bar.fillAmount = Mathf.Clamp01(pct / 100f);
|
|
}
|
|
|
|
public void Init(DateTime time,string path="",float angle=0,float dis=0)
|
|
{
|
|
timeText.text = time.ToString("yyyy-MM-dd HH:mm:ss");
|
|
if(path!="")
|
|
{
|
|
videoImage.gameObject.SetActive(true);
|
|
//NetworkCtrl.Instance.LoadImageToUIImageAsync(path, videoImage);
|
|
data.text="";
|
|
}
|
|
else
|
|
{
|
|
int type=DataManager.Instance.userInfo.unit_system;
|
|
string disStr="";
|
|
if(type==0)
|
|
{
|
|
disStr=dis.ToString("f1")+"m";
|
|
}
|
|
else
|
|
{
|
|
int lensFt=Mathf.RoundToInt((float)(dis * 3.28084));
|
|
disStr=lensFt+"ft";
|
|
}
|
|
videoImage.gameObject.SetActive(false);
|
|
data.text=$"{angle}° {disStr}";
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 视频项专用:绑定 url 与 下载/播放 两个按钮的回调
|
|
/// </summary>
|
|
/// <param name="url">视频源 url(.mp4 或 .h264)</param>
|
|
/// <param name="onDownload">点下载按钮</param>
|
|
/// <param name="onPlay">点播放按钮</param>
|
|
public void SetupVideo(string url, UnityEngine.Events.UnityAction onDownload, UnityEngine.Events.UnityAction onPlay)
|
|
{
|
|
videoUrl = url;
|
|
isVideo = true;
|
|
if (downloadButton != null)
|
|
{
|
|
downloadButton.onClick.RemoveAllListeners();
|
|
downloadButton.onClick.AddListener(onDownload);
|
|
}
|
|
if (playButton != null)
|
|
{
|
|
playButton.onClick.RemoveAllListeners();
|
|
playButton.onClick.AddListener(onPlay);
|
|
}
|
|
RefreshButtons();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据下载状态刷新按钮显示:未下载显下载、已下载显播放;非视频项隐藏两个按钮
|
|
/// </summary>
|
|
public void RefreshButtons()
|
|
{
|
|
if (downloadButton == null || playButton == null) return;
|
|
if (!isVideo)
|
|
{
|
|
downloadButton.gameObject.SetActive(false);
|
|
playButton.gameObject.SetActive(false);
|
|
return;
|
|
}
|
|
bool cached = Kill.Video.VideoCacheManager.IsCached(videoUrl);
|
|
downloadButton.gameObject.SetActive(!cached);
|
|
playButton.gameObject.SetActive(cached);
|
|
}
|
|
}
|
|
}
|
|
|