Логи молчат.
Код выполняется полностью.
На Windows всё работает
Этот же код, ранее, работал и на Linux, но с другим роликом.
Формат ролика ogv
Видео-кодек - Theora
Востановил Linux из backup до момента работающего ролика, не помогло.
Реализовывал работу плеера на событиях - результат тот же.
Синтаксис:
Используется csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Video;
public class video : MonoBehaviour
{
public RawImage image;
public VideoClip videoToPlay;
private VideoPlayer videoPlayer;
public VideoSource videoSource;
private AudioSource audioSource;
public Text text_;
private void OnEnable()
{
videoPlayer = new VideoPlayer();
//videoPlayer.source = VideoSource.Url;
//videoPlayer.url = "http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4";
StartCoroutine(playVideo());
}
private void OnDisable()
{
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
IEnumerator playVideo()
{
text_.text = text_.text + "/r/n/" + "1";
//Add VideoPlayer to the GameObject
videoPlayer = gameObject.AddComponent<VideoPlayer>();
text_.text = text_.text + "/r/n/" + "2";
//Add AudioSource
audioSource = gameObject.AddComponent<AudioSource>();
text_.text = text_.text + "/r/n/" + "3";
//Disable Play on Awake for both Video and Audio
videoPlayer.playOnAwake = false;
text_.text = text_.text + "/r/n/" + "4";
audioSource.playOnAwake = false;
text_.text = text_.text + "/r/n/" + "5";
audioSource.Pause();
text_.text = text_.text + "/r/n/" + "6";
//We want to play from video clip not from url
videoPlayer.source = VideoSource.VideoClip;
text_.text = text_.text + "/r/n/" + "7";
// Vide clip from Url
//videoPlayer.source = VideoSource.Url;
//videoPlayer.url = "http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4";
//Set Audio Output to AudioSource
videoPlayer.audioOutputMode = VideoAudioOutputMode.AudioSource;
text_.text = text_.text + "/r/n/" + "8";
//Assign the Audio from Video to AudioSource to be played
videoPlayer.EnableAudioTrack(0, true);
text_.text = text_.text + "/r/n/" + "9";
videoPlayer.SetTargetAudioSource(0, audioSource);
text_.text = text_.text + "/r/n/" + "10";
//Set video To Play then prepare Audio to prevent Buffering
videoPlayer.clip = videoToPlay;
text_.text = text_.text + "/r/n/" + "11";
videoPlayer.Prepare();
text_.text = text_.text + "/r/n/" + "12";
//Wait until video is prepared
WaitForSeconds waitTime = new WaitForSeconds(1);
text_.text = text_.text + "/r/n/" + "13";
while (!videoPlayer.isPrepared)
{
Debug.Log("Preparing Video");
//Prepare/Wait for 5 sceonds only
yield return waitTime;
//Break out of the while loop after 5 seconds wait
break;
}
text_.text = text_.text + "/r/n/" + "14";
Debug.Log("Done Preparing Video");
//Assign the Texture from Video to RawImage to be displayed
image.texture = videoPlayer.texture;
text_.text = text_.text + "/r/n/" + "15";
//Play Video
videoPlayer.Play();
text_.text = text_.text + "/r/n/" + "16";
//Play Sound
audioSource.Play();
text_.text = text_.text + "/r/n/" + "17";
Debug.Log("Playing Video");
while (videoPlayer.isPlaying)
{
Debug.LogWarning("Video Time: " + Mathf.FloorToInt((float)videoPlayer.time));
yield return null;
}
text_.text = text_.text + "/r/n/" + "18";
Debug.Log("Done Playing Video");
}
}
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Video;
public class video : MonoBehaviour
{
public RawImage image;
public VideoClip videoToPlay;
private VideoPlayer videoPlayer;
public VideoSource videoSource;
private AudioSource audioSource;
public Text text_;
private void OnEnable()
{
videoPlayer = new VideoPlayer();
//videoPlayer.source = VideoSource.Url;
//videoPlayer.url = "http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4";
StartCoroutine(playVideo());
}
private void OnDisable()
{
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
IEnumerator playVideo()
{
text_.text = text_.text + "/r/n/" + "1";
//Add VideoPlayer to the GameObject
videoPlayer = gameObject.AddComponent<VideoPlayer>();
text_.text = text_.text + "/r/n/" + "2";
//Add AudioSource
audioSource = gameObject.AddComponent<AudioSource>();
text_.text = text_.text + "/r/n/" + "3";
//Disable Play on Awake for both Video and Audio
videoPlayer.playOnAwake = false;
text_.text = text_.text + "/r/n/" + "4";
audioSource.playOnAwake = false;
text_.text = text_.text + "/r/n/" + "5";
audioSource.Pause();
text_.text = text_.text + "/r/n/" + "6";
//We want to play from video clip not from url
videoPlayer.source = VideoSource.VideoClip;
text_.text = text_.text + "/r/n/" + "7";
// Vide clip from Url
//videoPlayer.source = VideoSource.Url;
//videoPlayer.url = "http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4";
//Set Audio Output to AudioSource
videoPlayer.audioOutputMode = VideoAudioOutputMode.AudioSource;
text_.text = text_.text + "/r/n/" + "8";
//Assign the Audio from Video to AudioSource to be played
videoPlayer.EnableAudioTrack(0, true);
text_.text = text_.text + "/r/n/" + "9";
videoPlayer.SetTargetAudioSource(0, audioSource);
text_.text = text_.text + "/r/n/" + "10";
//Set video To Play then prepare Audio to prevent Buffering
videoPlayer.clip = videoToPlay;
text_.text = text_.text + "/r/n/" + "11";
videoPlayer.Prepare();
text_.text = text_.text + "/r/n/" + "12";
//Wait until video is prepared
WaitForSeconds waitTime = new WaitForSeconds(1);
text_.text = text_.text + "/r/n/" + "13";
while (!videoPlayer.isPrepared)
{
Debug.Log("Preparing Video");
//Prepare/Wait for 5 sceonds only
yield return waitTime;
//Break out of the while loop after 5 seconds wait
break;
}
text_.text = text_.text + "/r/n/" + "14";
Debug.Log("Done Preparing Video");
//Assign the Texture from Video to RawImage to be displayed
image.texture = videoPlayer.texture;
text_.text = text_.text + "/r/n/" + "15";
//Play Video
videoPlayer.Play();
text_.text = text_.text + "/r/n/" + "16";
//Play Sound
audioSource.Play();
text_.text = text_.text + "/r/n/" + "17";
Debug.Log("Playing Video");
while (videoPlayer.isPlaying)
{
Debug.LogWarning("Video Time: " + Mathf.FloorToInt((float)videoPlayer.time));
yield return null;
}
text_.text = text_.text + "/r/n/" + "18";
Debug.Log("Done Playing Video");
}
}