iPhoneUtils.PlayMovieURL showing a movie from a URL

Hi,

I am trying to show a movie from a URL, but also download it for next time use…
So first time, when the user watch the movie, it gets save on the iphone, then next time, it will load from the iPhone rather than fetching the same movie file from the internet again…

Is there a way to do that ?

If not, then i need a suggestion on how i can charge for watching the movie, it i charge a none consumable, it doesn’t make sense, because the user doesn’t really own the file, and it still on a remote URL, when the user has paid for it.

If i charge a consumable, then what if the internet cuts off, then the user just wasted his money…

I looked into the renewable and none renewable, and i am still confused on which one is more suitable for such thing…

This is an app by the way, with video tutorials , that the user gets to pay for each to watch …

Any help will be appreciated …

Sure, no problem there, just use file:// instead of http:// and ensure to store it in a for you reachable place (the apps documents or cache folder)

as for consumables: at least I (unsure on apples stance) wouldn’t use consumables linked directly to download as a failure of connection has to be expected with mobiles. you would eat consumables for them buying the product and then having it or not having it or the consumable giving something else thats persistent.
With persistent I mean something thats at least temporal persistent (like available for 48h after buying or whatever)

When you say store it? What did you mean by that? Did you mean when the user plays the movie from the URL, then it automatically saves into the documents folder? Or Cash folder?
But then how do I grab it from the documents or cash folder?
Also doesn’t the cash get erased after a while or after a restart or something?

Here is the senario,

1- On user touch hit test a button
2- iphoneutil.playmovieurl(URL.:color.:modeFull)

Now there is no way that I know that would watch for a movie interface Done button pressed.
So I won’t know if the movie successfully played, done or partially done.

But again,
Should I sat instead of item number 2 above, next time the user press the button run this line
2- iphoneutil.playmovie(file//filename.mov.:color.:modeFull)

I hope I am making sense and hopefully I can get a solution.

Any help would be appreciated…

with store I mean: use WWW to download the file, use System.IO to store it on the device and then use the playmovieurl to get it from there.

Okay here is what i have done,

//////////////////////
in Unity
/////////////////////
var www: WWW;

function SaveMovieAndLoad() {
var url = “http://domain/Movie/TestingMovie.mov”;
www = new WWW(url);
var progress1 = www;

var fileName : String = Application.persistentDataPath + “/” + “TestingMovie.mov”;
var cache = new System.IO.FileStream(fileName, System.IO.FileMode.Create);
for(var i = 0; i < progress1.bytes.length; i++){
cache.Write(progress1.bytes, 0, progress1.bytes.Length);
}

print(progress1.progress);

while (!progress1.isDone)
yield;

cache.Close();
Debug.Log("Cache saved: " + fileName);
print(“file download is done”);

iPhoneUtils.PlayMovie((“TestingMovie.mov”), Color.black, iPhoneMovieControlMode.Full);
}

/////////////////////
in Xcode
////////////////////

Cache saved: /var/mobile/Applications/BAD0E1A0-FD53-4033-915B-D99C718173B3/Documents/TestingMovie.mov

(Filename: /Applications/buildAgent/work/6bc5f79e0a4296d6/Projects/…/Runtime/Export/Generated/BaseClass.cpp Line: 2505)

file download is done

//////////////////

But nothing happens and the movie does not play on screen!

I have been trying all day with the last line of code to get the movie to play, I have read 10s of pages from unity forum and answers but no luck in finding an answer!

Anyone out there?

I might be missing something simple, but can’t get to it!!!

playmovie with just the name only works if it is in the streamingassets folder and to that one you can’t write on the device.

you definitely need to use PlayMovieUrl so you can use the file:// based url to the file if you cached it by writting it onto the disk.

but your code is incorrect, that will never work like that anyway.
Wait for WWW to finish (yield www) and once done write the whole movie in one go with System.IO.File.WriteAllBytes(fileName, www.bytes) for example.

the reason the code won’t work is that at the place you look to write something you don’t wait at all nor do you check if its done or anything … all it does is deadlock the application. Also trying to accessing bytes.length before you even have all the data isn’t going to work out, especially in this case where bytes is empty at the point you get there (at worst even null)

First of all, i would like to thank you for the information you have provided me thus far, at least you put me on the right direction , however i got an error after correcting my code…

Here is what i have in Unity
///////////////////////////////////////
var url = “http://domain/Movie/TestingMovie.mov”;
www = new WWW(url);
var progress1 = www;

print(progress1.progress);

while (!progress1.isDone)
yield;

var fileName : String = Application.persistentDataPath + “/” + “TestingMovie.mov”;
print(" progress1.bytes.length = "+progress1.bytes.length);

System.IO.File.WriteAllBytes(fileName, progress1.bytes);

Debug.Log("Cache saved: " + fileName);
print(“file download is done”);

yield WaitForEndOfFrame();

if (System.IO.File.Exists(“file://” + Application.persistentDataPath + “/TestingMovie.mov”))
{
print(" file does exist");
}
else
print(" file does not exist");

iPhoneUtils.PlayMovieURL((“file://” + Application.persistentDataPath + “TestingMovie.mov”), Color.black, iPhoneMovieControlMode.Full);

This is what i have output in Xcode
///////////////////////////////////////////////////
(Filename: /Applications/buildAgent/work/6bc5f79e0a4296d6/Projects/…/Runtime/Export/Generated/BaseClass.cpp Line: 2505)

progress1.bytes.length = 63708

(Filename: /Applications/buildAgent/work/6bc5f79e0a4296d6/Projects/…/Runtime/Export/Generated/BaseClass.cpp Line: 2505)

Cache saved: /var/mobile/Applications/BAD0E1A0-FD53-4033-915B-D99C718173B3/Documents/TestingMovie.mov

(Filename: /Applications/buildAgent/work/6bc5f79e0a4296d6/Projects/…/Runtime/Export/Generated/BaseClass.cpp Line: 2505)

file download is done

(Filename: /Applications/buildAgent/work/6bc5f79e0a4296d6/Projects/…/Runtime/Export/Generated/BaseClass.cpp Line: 2505)

file does not exist

////////////////////////////////////////////////

Not sure what’s going on, even though the correct bytes.length is showing, then i ask it to write all bytes to the file name, but still the files does not exist, thus it does not play!

Something i am missing ?

Any idea ???

At least I want to know if it is possible to download a mov file, then save it to the docs folder on the iPhone or not???

I can’t seem to find the answer anywhere!

We’re having this exact same issue. In fact, we can’t even download either an asset bundle or a mov file. It looks like Dreamora has a lot of confidence on the subject and your help would be greatly appreciated.

Our problem is with Android and the 50MB limit. We are experiencing 20-50 support emails a day and hundreds of cancelled orders because users can not download our 50MB APK file. Our game has exactly 20MB of cinematics and this would be a great solution, but doesn’t seem to work. Worst of all, the test loop is slow; the only way to really test is to build on the device, so each attempt is a 5 minute loop.

Here’s our code:

var url = “http://fenixfire/bundles/RobotoCinematics.unity3d”;
var www : WWW;

function Awake()
{
www = new WWW (url);
yield www;
}

//to show download progress
function OnGUI ()
{
GUI.Box(Rect(300, 0, 100, 20),“” + www.progress );
}

This code reports “0” in the “www.progress” GUI field. Any thoughts? And this is just step one. Then next step would be writing to either the internal memory or the SD card, which the consumer will expect to have an option for. Step three would be to load and play the asset, which nobody seems to be able to do on Android.

Thanks in advance for any help,
Brian

Alright. After much trial and error testing, I figured this out. I uploaded our movie file to a different directory on our web server and now it works, no idea why one folder would work and another doesn’t.

This C# code downloads the movie file from our web server. Once the file is fully downloaded it is written to the SD card for Android (haven’t tested on iOS yet). I then added a GUI button to play the video - again, after much trial an error this path format is what worked for us.

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using UnityEngine;
using System;
using System.Collections;
using System.IO;

public class DownloadAssets : MonoBehaviour
{
public WWW www;

// Use this for initialization
void Start ()
{
www = new WWW(“http://www.fenixfire.com/images/Final_RocketExplosion.mp4”);

StartCoroutine(WaitForRequest(www));
}

IEnumerator WaitForRequest(WWW www)
{
yield return www;

// check for errors
if (www.error == null)
{
Debug.Log("WWW Ok!: " + www.text);
} else {
Debug.Log("WWW Error: "+ www.error);
}

if(www.isDone)
{
Debug.Log(“DONE!!!”);
System.IO.File.WriteAllBytes(Application.persistentDataPath + “/Final_RocketExplosion.mp4”, www.bytes);
}
}

void OnGUI()
{
GUI.Box(new Rect(300f, 0f, 100f, 20f),“” + www.progress );

if(GUI.Button(new Rect(60f,100f,50f,50f),“ver1”))
iPhoneUtils.PlayMovieURL(“file://” + Application.persistentDataPath + “/Final_RocketExplosion.mp4”, Color.black, iPhoneMovieControlMode.CancelOnTouch);

}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

The working code in this Thread was very helpful. Thanks.
One thing I found with PlayMovieURL() (using Unity 3.4 for Android) is that the older Samsung Galaxy Tab GT-P1010 (7 inch) does not like “file://” prepended on URLs. Movie files downloaded (cached) to Application.persistentDataPath can be found and played by PlayMovieURL() WITHOUT the “file://” appended (Application.persistentDataPath+fileName), but with the “file://” at the front, movies are not found/played.

Thats cause this is an iOS thread :slight_smile:
On android its called slightly different (the only platform though where this is the case) cause the android http requester works a bit different and unity always relies on the native one