好吧我以前从来没有使用过统一的视频播放器,设法让它在Android和编辑器上运行但音频无法播放,我从网址获取视频并将视频播放器指向附加到音频源的音频源与视频播放器组件相同的对象附加,我已经按照这个链接Using new Unity VideoPlayer and VideoClip API to play video的建议,但没有任何喜悦,下面是如何即时调用它提到视频的工作顺序,但音频没有,任何人都可以帮助
private AudioSource audio;
private VideoPlayer screen;
screen = go.GetComponentInChildren<VideoPlayer>();
audio = go.GetComponentInChildren<AudioSource>();
audio.playOnAwake = false;
screen.source = VideoSource.Url;
screen.url = videoObj.VideoURL;
screen.audioOutputMode = VideoAudioOutputMode.AudioSource;
screen.EnableAudioTrack (0,true);
screen.SetTargetAudioSource (0,audio);
screen.Prepare ();
screen.Play();
audio.Play ();
修改
根据下面的评论我添加了一些信息并澄清了一些要点,因此统一版本是2017年音频在编辑器或任何设备上播放但视频在编辑器和设备上运行良好,这是一个我正在尝试https://storage.googleapis.com/godapp-a3e4b.appspot.com/jacopatrolmontage.mp4的网址,这里是完整的代码,或者我正在使用的方法请不要拆开其他我可能做错的东西,因为我宁愿新的团结和C#
public void showPlayer(VideoObjects videoObj)
{
if (GameObject.Find("videoPlaner(Clone)") == null)
{
//may need scene.isValid
GameObject go = Instantiate(videoPlayer);
go.transform.SetParent(canvas.transform, false);
screen = go.GetComponentInChildren<VideoPlayer>();
audio = go.GetComponentInChildren<AudioSource>();
//audio = go.AddComponent<AudioSource>();
fsscreenBool = true;
screenSize = go.GetComponent<Transform> ().localScale;
screenPosition = go.GetComponent<Transform> ().localPosition;
canvasRectTransformScale = go.GetComponentInParent<RectTransform>
();
foreach (Transform tr in go.transform)
{
if (tr.gameObject.tag == "play")
{
Button play = tr.GetComponent<Button>();
AddPlayListener(play, screen);
preparePlayer(play,screen.isPlaying);
}
if (tr.gameObject.tag == "fullscreen")
{
Button fullScreen = tr.GetComponent<Button>();
AddFSListener(fullScreen, go);
}
if (tr.gameObject.tag == "forward")
{
}
if (tr.gameObject.tag == "rewind")
{
}
if (tr.gameObject.tag == "vidtitle")
{
tr.GetComponent<Text>().text = videoObj.VideoTitle;
}
if (tr.gameObject.tag == "loading")
{
loading = tr.gameObject;
}
}
}
else{
//print("it exists");
GameObject existingGO = GameObject.Find("videoPlaner(Clone)");
screen = existingGO.GetComponentInChildren<VideoPlayer>();
loading.SetActive (true);
foreach (Transform tr in existingGO.transform)
{
if (tr.gameObject.tag == "play")
{
}
if (tr.gameObject.tag == "fullscreen")
{
checkScreen (existingGO);
}
if (tr.gameObject.tag == "forward")
{
}
if (tr.gameObject.tag == "rewind")
{
}
if (tr.gameObject.tag == "vidtitle")
{
tr.GetComponent<Text>().text = videoObj.VideoTitle;
}
if (tr.gameObject.tag == "loading")
{
}
}
}
screen.source = VideoSource.Url;
screen.url = videoObj.VideoURL;
screen.audioOutputMode = VideoAudioOutputMode.AudioSource;
screen.EnableAudioTrack (0,true);
screen.SetTargetAudioSource (0,audio);
screen.Prepare ();
audio.Play ();
screen.Play();
}
答案 0 :(得分:1)
在致电screen.Prepare ()
和screen.Play()
之前,您正在呼叫audio.Play ()
而不是等待其准备。您还设置了audio.playOnAwake = false;
但未对视频执行此操作。您还应该在playOnAwake
上将视频设为false。在播放前加载视频时间。
screen.Prepare();
//Wait until video is prepared
while (!screen.isPrepared)
{
yield return null;
}
//Assign the Texture from Video to RawImage to be displayed
image.texture = videoPlayer.texture;
//Play Video
screen.Play();
//Play Sound
audio.Play();
您可能希望将音频变量重命名为其他内容,因为这是已声明为MonoBehaviour
的已弃用变量。 最后,使用您链接的问题中answer的代码。应该可以使用RawImage
播放视频。
它仍然适用于原始图像,我有一个重复的视频
一旦发生在我身上,我意识到Unity在游戏对象上寻找一个Renderer
,其中任何脚本中都附有任何VideoPlayer
代码,然后自动更新每个Texture
帧。我认为他们这样做是为了简化VideoPlayer
的使用。
您可以将该脚本附加到没有Renderer
的空GameObject,然后您可以继续将RawImage
放在编辑器的图像插槽中。没有重复。
答案 1 :(得分:0)
如果没有播放音频,请在No signature of method: com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase.setPropertyValue() is applicable for argument types: (java.lang.String, java.util.ArrayList) values: [RowData, [18144046 5276601 CI DRVD, 18144050 5276601 CI DRVD, ...]]
Possible solutions: setPropertyValue(java.lang.String, java.lang.String), getPropertyValue(java.lang.String)
之前添加此行:
screen.prepare()
答案 2 :(得分:0)
videoPlayer.controlledAudioTrackCount = 1;应该在使用VideoSource.Url模式时写入。