I was working on quiz game and for which for few video questions, I required to download a video file and play it on the screen so a person can able to give answer for the question.
Before quiz game start, I want to pre-download the video file so when question will come up, it will directly start playing a video.
I don’t want to save the video file because its not required, just runtime I want to pre-load the video file and play it.
This is test video MP4 file link, files already uploaded on web server.
I don’t know how to achieve this so please guide me for this, thank for your effort to read this question.
After doing some Google efforts I can able to play a single video using Video Player component.
This kind of code I have written:
public class VideoDownloaderTest : MonoBehaviour
{
VideoPlayer videoPlayer;
private void Awake()
{
videoPlayer = GetComponent<VideoPlayer>();
}
private void Start()
{
videoPlayer.Prepare();
videoPlayer.errorReceived += VideoPlayer_errorReceived;
videoPlayer.prepareCompleted += VideoPlayer_PrepareCompleted;
}
private void VideoPlayer_errorReceived(VideoPlayer source, string message)
{
Debug.Log("message: " + message);
}
private void VideoPlayer_PrepareCompleted(VideoPlayer source)
{
Debug.Log("video loading complete...");
videoPlayer.Play();
}
}
This is working properly, its playing on the spot, as I execute videoPlayer.Play() method.
For single video this is working properly but can I make multiple video players?
Because I am working on quiz game so multiple video questions will come.
Can you not just change the video player URL value?
Basically I want to preload all my videos so I required different Video Players for each URL.
The Video Player is just a component… I don’t see why you can’t just put each one on a different Video Player component.
Yes, I mean the same, I have to create separate game object and video player component for each url, I have so I preload them.
GameObject videoPlayerObj = new GameObject("VideoPlayer");
videoPlayer = videoPlayerObj.AddComponent<VideoPlayer>();
Now am I correct? or doing some mistakes