Hi,
I’m trying to load an external movie (.mp4) in a folder of my PC but it doesn’t work, here is my code:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.IO;
public class LoadFilesController : MonoBehaviour {
string path = "C:/Video/";
string url = "file:///C:/Video/";
string fileName = "video.mp4";
string[] files;
RawImage player;
AudioSource sound;
MovieTexture movie;
void Start () {
player = GetComponent<RawImage> ();
sound = GetComponent<AudioSource> ();
files = Directory.GetFiles (path);
foreach (string file in files){
//Debug.Log(file);
}
StartCoroutine (loadMovie ());
}
public void setMovie(string movieName){
fileName = movieName;
StartCoroutine (loadMovie ());
}
IEnumerator loadMovie(){
WWW www = new WWW (url + fileName);
yield return www;
Debug.Log (www.movie.duration + " <--- wwww");
if (www.error != null) {
Debug.Log ("Error: Can't laod movie! - " + www.error);
yield break;
} else {
MovieTexture video = www.movie as MovieTexture;
Debug.Log("Movie loaded");
Debug.Log(www.movie);
movie = video;
setMovie();
playMovie();
}
}
public void setMovie(){
Debug.Log (movie.name + " ------");
player.texture = movie;
sound.clip = movie.audioClip;
}
public void playMovie(){
movie.Play ();
sound.Play ();
}
public void pauseMovie(){
movie.Pause ();
sound.Pause ();
}
}