Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Video 视频播放器协同程序问题_Video_Unity3d_Runtime_Unityscript_Coroutine - Fatal编程技术网

Video 视频播放器协同程序问题

Video 视频播放器协同程序问题,video,unity3d,runtime,unityscript,coroutine,Video,Unity3d,Runtime,Unityscript,Coroutine,我有一个协同程序,在运行时通过www类下载一个.ogg文件,这目前确实不一致 视频旨在以正常大小()显示,有时这是可行的。但是,视频通常会显示在屏幕上 在我看来,这在很大程度上是因为视频没有完全使用当前的协同程序下载。我已经尽我所能地关注文档(ScriptRef/www电影),但没有任何效果,如果有人对为什么会发生这种情况有任何建议,我将非常感激 注意:在uJS中编写脚本 多谢各位 瑞安 函数loadContextVideo(texLocation:String) { var wwwDirect

我有一个协同程序,在运行时通过www类下载一个.ogg文件,这目前确实不一致

视频旨在以正常大小()显示,有时这是可行的。但是,视频通常会显示在屏幕上

在我看来,这在很大程度上是因为视频没有完全使用当前的协同程序下载。我已经尽我所能地关注文档(ScriptRef/www电影),但没有任何效果,如果有人对为什么会发生这种情况有任何建议,我将非常感激

注意:在uJS中编写脚本

多谢各位

瑞安

函数loadContextVideo(texLocation:String)
{
var wwwDirectory=“文件:/”+texLocation;
var vidTex=www.movie;//方法01[使用局部变量]
//vidTex=www.movie;//方法02[使用公共变量]
而(!vidTex.isReadyToPlay){/****问题协同程序*****
产生www;
国际单项体育联合会(www.isDone)
{
打破
}
}
var texWidth=vidTex.width;
var texHeight=vidTex.height;
Log(“texWidth:+texWidth+”texHeight:+texHeight);
//检查img尺寸
var mvMaxWidth=imgRect.rect.width;
var mvMaxHeight=imgRect.rect.height;
Log(“mvMaxWidth:+mvMaxWidth+”mvMaxHeight:+mvMaxHeight);
如果(texHeight>mvMaxHeight)
{
var scaleHFactor=mvMaxHeight/texHeight;
texHeight=texHeight*比例因子;
texWidth=texWidth*比例因子;
}
如果(texWidth>mvMaxWidth)
{
var scaleWFactor=mvMaxWidth/texWidth;
texHeight=texHeight*scaleWFactor;
texWidth=texWidth*scaleWFactor;
}
Log(“texWidth:+texWidth+”texHeight:+texHeight);
imgRect.sizeDelta=新矢量2(texWidth,texHeight);
//视频图文分配
var imgView:UI.RawImage=imageView.GetComponent.(;//方法01[使用局部变量]
//var imgView=imageRender;//方法02[使用公共变量]
imgView.texture=vidTex;
//视音频分配
var vidAudio:AudioSource=imageView.GetComponent.();
vidAudio.clip=vidTex.audioClip;
//curVideo=可视图文;
vidTex.Play();
vidAudio.Play();
}

多亏@fafase的建议,问题似乎是“下载准备就绪和视频文件准备就绪之间存在帧差”。解决此问题的答案是检查www.file是否已下载完毕,以及视频文件是否已准备好播放,如下代码所示:

函数loadContextVideo(texLocation:String)
{
var wwwDirectory=“文件:/”+texLocation;
var www:www=new www(wwwDirectory);
vidTex=www.movie;
//而(!vidTex.isReadyToPlay){//问题协同程序
//产生www;
//国际单项体育联合会(www.isDone)
//		{
//中断;
//		}
而(!www.isDone&&!vidTex.isReadyToPlay){//answer coroutine
产生www;
如果(www.isDone&&vidTex.isReadyToPlay)
{
打破
}
}
var texWidth=vidTex.width;
var texHeight=vidTex.height;

//其余的代码仍在继续…
“unityscript”现在已被弃用,并将从Unity中删除。使用u/s进行类似操作将非常困难(幸运的是c#实际上要容易得多)你好@Joe Blow,谢谢你的建议;你在另一个网站上给了我类似的反馈,虽然我认识到需要从uJS进行更改,但我当前项目中的时间限制不允许我选择C。你能告诉我当前协同程序中的逻辑在哪里吗?它似乎非常接近,但不可靠。请尝试删除www.isDone check.Hi@fafase,感谢您的回复!我们已经测试了您的建议,同样的问题似乎仍然存在。您能解释您的逻辑吗?非常感谢。
 function loadContextVideo(texLocation : String)
 {
     var wwwDirectory = "file://" + texLocation; 

     var vidTex = www.movie;    //method 01 [using local variables]
 //    vidTex = www.movie;    //method 02 [using public variables]

     while(!vidTex.isReadyToPlay){ //****PROBLEM COROUTINE*****
         yield www;
         if (www.isDone)
         {
             break;
         }
     }

     var texWidth = vidTex.width;
     var texHeight = vidTex.height;
     Debug.Log("texWidth: " + texWidth + " texHeight: " + texHeight);

     //check img sizes
     var mvMaxWidth = imgRect.rect.width;
     var mvMaxHeight = imgRect.rect.height;
     Debug.Log("mvMaxWidth: " + mvMaxWidth + " mvMaxHeight: " + mvMaxHeight);

     if (texHeight > mvMaxHeight)
     {
         var scaleHFactor = mvMaxHeight /texHeight;
         texHeight = texHeight * scaleHFactor;
         texWidth = texWidth * scaleHFactor;        
     }
     if (texWidth > mvMaxWidth)
     {
         var scaleWFactor = mvMaxWidth /texWidth;
         texHeight = texHeight * scaleWFactor;
         texWidth = texWidth * scaleWFactor;
     }
     Debug.Log("texWidth: " + texWidth + " texHeight: " + texHeight);
     imgRect.sizeDelta = new Vector2(texWidth, texHeight);

     //Video Tex assign
     var imgView : UI.RawImage = imageView.GetComponent.<RawImage>(); //method 01 [using local variables]
 //    var imgView = imageRender; //method 02 [using public variables]
     imgView.texture = vidTex;

     //Video Audio assign
     var vidAudio : AudioSource = imageView.GetComponent.<AudioSource>(); 
     vidAudio.clip = vidTex.audioClip;

     //curVideo = vidTex;
     vidTex.Play();
     vidAudio.Play();    
 }