当前位置:   article > 正文

audio unity 加速_unity中如何实现调整视频播放速度的功能?

unity 不掉帧加速视频播放

using UnityEngine;

using System.Collections;

public class VideoPlayer : MonoBehaviour {

// 控制器将传来的信息DtoVideo _dtoVideo =null;// 视频源信息public DtoVideo dtoVideo

{

get { return this._dtoVideo;}

set { _dtoVideo = value;}

}

Status _states=Status.Pause;// 视频状态,初始化为暂停public Status states

{

get { return this._states;}

set { _states = value;}

}

int _goFrame=0;// 程序从哪帧开始public int goFrame

{

get { return this._goFrame;}

set { _goFrame = value;}

}

// 自己用的信息GameObject plane;// 背景面片Texture tx;// 贴图AssetBundle assetBundle;// 资源包int bag=0;// 现在加载的第几个包string bags="";// 现在加载的包名int frame=0;// 现在渲染第几帧string loads="";// 现在加载的物体名int bagFrame=0;// 已渲染到包中的第几张图GameObject ownController;// 控制器public bool open=false;// 是否打开播放器

// Use this for initializationvoid Start ()

{

Initialize();// 初始化//FullScreen(plane);// 全屏播放}

// Update is called once per framevoid Update ()

{

if(states==Status.StartOver)// 如果视频重播{

// 释放内存assetBundle.Unload(false);

Resources.UnloadUnusedAssets();

}

}

void FixedUpdate()

{

if(states==Status.Play && open==true)// 如果视频继续播放{

if(bags=="")// 初始化{

CalcaulteBag(goFrame);

//bags=bag.ToString("d2")+".assetbundle";LoadTexture(dtoVideo.Path,bags);// 加载资源包assetBundle.Load(loads);// 加载图片}

loads=frame.ToString("d6");// 物体名为帧数补0,到6位数为止RendererTexture(plane,loads);// 渲染ownController.GetComponent().frameVideo=frame;// 返回当前帧数给控制器frame++;// 加帧bagFrame++;// 加包中帧if(bagFrame>=dtoVideo.Each & bag

bag++;// 加包bagFrame=0;// 包中帧归位0// 释放内存assetBundle.Unload(false);

Resources.UnloadUnusedAssets();

bags=

#if UNITY_ANDROID"Android"+bag.ToString("d2")+".assetbundle";

#elif UNITY_STANDALONE_WIN || UNITY_EDITORbag.ToString("d2")+".assetbundle";

#elsebag.ToString("d2")+".assetbundle";

#endifLoadTexture(dtoVideo.Path,bags);// 读包//Debug.Log("change bags:"+bags);}

if(frame>=dtoVideo.Tote)// 循环播放{

frame=0;// 帧数归位0bag=0;// 包归位0bagFrame=0;// 包中帧归位0ownController.GetComponent().round++;// 加圈数// 释放内存assetBundle.Unload(false);

Resources.UnloadUnusedAssets();

bags=

#if UNITY_ANDROID"Android"+bag.ToString("d2")+".assetbundle";

#elif UNITY_STANDALONE_WIN || UNITY_EDITORbag.ToString("d2")+".assetbundle";

#elsebag.ToString("d2")+".assetbundle";

#endifLoadTexture(dtoVideo.Path,bags);// 读包//Debug.Log("reload bags:"+bags);//Debug.Log("already finish round:"+ownController.GetComponent().round);}

}

}

/// /// 初始化/// public void Initialize()

{

string PlaneName = "background";// 背景面片名plane=GameObject.Find(PlaneName);

if(plane==null)

{

Debug.Log("VideoPlayer can't find background plane");

}

string ControllerName="own controller";// 控制器载体名ownController=GameObject.Find(ControllerName);

if(ownController==null)

{

Debug.Log("VideoPlayer can't find controller");

}

// 获取控制器传来的信息states=ownController.GetComponent().status;

Debug.Log("initialize video player");

}

/// /// 计算第几帧开始的时候处于哪个包/// /// 初始帧public void CalcaulteBag(int goFrame)

{

frame=goFrame;// 当前帧为初始帧bag=goFrame/dtoVideo.Each;// 当前包=初始帧/每包帧数 bags=

#if UNITY_ANDROID"Android"+bag.ToString("d2")+".assetbundle";

#elif UNITY_STANDALONE_WIN || UNITY_EDITORbag.ToString("d2")+".assetbundle";

#elsebag.ToString("d2")+".assetbundle";

#endif}

/// /// 渲染贴图/// /// 面片/// 贴图名public void RendererTexture(GameObject plane,string loadname)

{

tx = assetBundle.Load(loadname) as Texture;

plane.renderer.material.mainTexture=tx;

}

/// /// 加载背景序列图资源/// /// 路径名/// 包名public void LoadTexture(string pathURL,string abName)

{

assetBundle = AssetBundle.CreateFromFile(pathURL+ abName);

if(assetBundle==null)

{

Debug.Log("assetBundle doesn't exist");

}

}

/// /// 全屏播放/// /// 背景面片public void FullScreen(GameObject plane)

{

if(plane!=null)

{

Screen.SetResolution(1366,768,true);

plane.transform.localScale=new Vector3(1.366f,1,0.768f);

Debug.Log("background full screen");

}

}

/// /// 释放AssetBundle/// public void CleanAssetBundle()

{

// 释放内存assetBundle.Unload(false);

Resources.UnloadUnusedAssets();

}

}

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/114121?site
推荐阅读
相关标签
  

闽ICP备14008679号