- Home /
Bundle up a movie file for handheld
From what I understand, currently (as of 3.5 beta) we can only play movies in iPhone / Android that are inside Assets/StreamingAssets
or directly from a URL.
I want to be able to stream the video from a URL while caching it up, like in a bundle. Or at very least just be able to download the bundle so every time I play the movie after the first time it will already be local. Is this possible?
When I try to build the bundle (just like we already do for many different assets) I get a dreaded `'MovieTexture' is not supported when building for Android.`. Though I haven't tried it on iPhone build yet, I bet it'd be the same.
Any luck with this? I am trying to do the same thing.
There you go, @matrix211v1 - the answer has been posted quite a while ago.
Answer by cregox · Jan 14, 2013 at 11:11 AM
Can't remember exactly when or how Leandro got to this solution.
Basically, use `www` to download, then `Handheld.PlayFullScreenMovie` to play. With a magical setting on iPhone:
private Color bgColor = Color.black;
private FullScreenMovieControlMode controlMode = FullScreenMovieControlMode.Full;
private FullScreenMovieScalingMode scalingMode = FullScreenMovieScalingMode.AspectFill;
private string videoFile = Application.persistentDataPath + "/your-video-file.mp4";
IEnumerator DownloadAndPlayVideo () {
string playVideoFile = videoFile;
#if UNITY_IPHONE
playVideoFile = "file://" + videoFile;
#end if
WWW www = new WWW("http://www.example.com/video.mp4");
yield return www;
if (www != null && www.isDone && www.error == null) {
FileStream stream = new FileStream(videoFile, FileMode.Create);
stream.Write(www.bytes, 0, www.bytes.Length);
stream.Close();
}
Handheld.PlayFullScreenMovie(playVideoFile, bgColor, controlMode, scalingMode);
}
As the playing part implies, this is for handhelds only. It won't work anywhere else. Though we'd "just" need to replace Handheld
with MovieTexture
, AudioSource
and maybe yet another www
(haven't tested if it'd work with same one).
This solution works for me. To check if you've already downloaded the file, use System.IO.File. If it's true, you don't need to download and can skip straight to video playback.
System.IO.File.Exists(videoFile);
For some reason File.Exist was always returning true to me so i used:
using System.Linq;
string[] files = Directory.GetFiles(Application.persistentDataPath);
if (files.Contains(playVideoFile))
{
}
Just in case someone else runs into this problem... And thanks for this Awesome code <3
That's right @bWard. I don't want to post the whole thing here else it gets too big, but there are many things that can be done to optimize it! ;-)
Answer by DVFrance · Jan 14, 2013 at 10:16 AM
Hi,
I'm trying to play a video on android to, as I read we need to use this :
But for me it still not work so if you found a way ...
Yes, we've found a way... $$anonymous$$eanwhile, this is far from being an answer, although it's the same path we went to indeed. Any way, you should change this to a simple comment! ;-)
Hi Cawas and tks for your answer.
I tried this but I still can't play the video, I have no error, no warning, the scene run but the video still not play.
I maybe found a way with this Universal_Video_Texture_LITE but I didn't try it yet. I'll tell you what going on :)
Back from vacations, @awesomealex ! I haven't posted a whole functioning script there. Just pointers on how to do it. Probably you did something wrong along the way... You could try posting a new question about it and link to it from here, so I can see it. But I assure you there's no need of anything but Unity to make it work. No addons or plugins what so ever.