0

I am trying to get a video (.ogv) from the Streaming Assets folder, apply it on to a surface and play it. (C# code added below) - Unity 5 Personal

void Start () {
 private MovieTexture myMoviePlayerTexture;

 string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, "test.ogv");

 WWW www = new WWW("file:///" + filePath);
 Renderer r = GetComponent<Renderer>();
 r.material.mainTexture = www.movie;
 www.movie.Play();
}

C# Script added to a simple plane.

However when I add the MovieTexture to a plane (from assets folder) it plays without any problems.

((MovieTexture)GetComponent<Renderer>().material.mainTexture).Play();

edit: the Problem: the video does not play from the Streaming Assets folder, it appears as if a material is loaded but it does not play.

Any help appriciated. Thanks.

EDIT

This is the game view: link and this is the folder structure link nothing fancy just some test videos

Programmer
  • 121,791
  • 22
  • 236
  • 328
Zinox
  • 519
  • 9
  • 24
  • What's the problem? You never explained what problems you are having – Programmer Mar 20 '17 at 17:40
  • @programmer Sorry, The video does not play. It appears that some material is loaded but it does not play fromt he Streaming Assets folder – Zinox Mar 20 '17 at 18:01
  • What platform are you testing this on? Can you put a screenshot of what the folder you put the video in looks like? – Programmer Mar 20 '17 at 18:52
  • @Programmer This is the game view: [link](http://imgur.com/CJ5NGTx) and this is the folder structure [link](http://imgur.com/htDmCtk) nothing fancy just some test videos – Zinox Mar 21 '17 at 09:02
  • @Programmer I have also tried the Assets > StreamingAssets path but to no avail – Zinox Mar 21 '17 at 09:23

1 Answers1

4

The code in your question is not even compiling. There are so many errors.

Anyways, don't play the video directly from the WWW object with www.movie.Play();. Get the MovieTexture from WWW first then play the video from there. Also, check if MovieTexture.isReadyToPlay is true before playing the video. You can do this in a coroutine or the Update() function.

Make sure that the test.ogv video is in the StreamingAssets folder. Your screenshot does not show what's inside the StreamingAssets folder.

Finally, playing video on a plane is now old. You can play Video on Unity's RawImage which is easier to work with in Unity.

I can't tell which Unity 5 version you are using but please update to 5.5 or above then use the code below:

MovieTexture myMoviePlayerTexture;
void Start()
{
    string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, "test.ogv");

    WWW www = new WWW("file:///" + filePath);
    Renderer r = GetComponent<Renderer>();
    myMoviePlayerTexture = www.GetMovieTexture();

    r.material.mainTexture = myMoviePlayerTexture;
}

void Update()
{
    if (myMoviePlayerTexture.isReadyToPlay && !myMoviePlayerTexture.isPlaying)
    {
        myMoviePlayerTexture.Play();
    }
}

It's worth noting that MovieTexture is now deprecated. See this post for the newsiest method to play video.

Community
  • 1
  • 1
Programmer
  • 121,791
  • 22
  • 236
  • 328
  • Thank you for your reply and solution. I want to play the video on an object, will that still be possible with RawImage? I tried using your solution but I am getting an error [link](http://imgur.com/niaoUj3) for the www.GetMovieTexture(); line. I am using Unity 5.5.2f1. – Zinox Mar 21 '17 at 17:31
  • If you just want to play video then use RawImage. It will show on the screen. If you want the video to show on a 3D Object like plane or cube then use the solution in my answer. I don't know what you are doing but before RawImage, playing video with plane was almost the only way to display the video. This is not true anymore with the RawImage. The decision is totally up to you. – Programmer Mar 21 '17 at 17:35
  • Sorry for that error. I used Unity 5.6 to make this solution. You can replace that part with `www.movie`. – Programmer Mar 21 '17 at 17:37
  • Thank you, Trying your solution now and downloading the 5.6beta. – Zinox Mar 21 '17 at 17:57
  • 1
    Thank you, I think this will help well in what I am trying to achieve. – Zinox Mar 22 '17 at 08:52