Home > other >  Pack the Unity Android apk download video problem
Pack the Unity Android apk download video problem

Time:09-21

Unity with vuforia developing an Android mobile AR Application, function: scan has been upload good pictures and related video playback, if the video haven't played before, the loading video playing and downloaded from the server to the Application. The persistentData path to save, if played before, direct broadcast local video (i.e. Application. PersistentData path), there is now a problem: loading video playback can be download from the server to the Application. The persistentData path, how to download? I know that kind of WWW has the properties of a byte array type bytes don't mean to download a video into a byte array, and then convert byte array to video? I found several related tutorial on the Internet are almost download images on the server (the official document is loading pictures of https://docs.unity3d.com/540/Documentation/ScriptReference/WWW.html and the http://blog.csdn.net/hany3000/article/details/25978395 loading video I was accomplished using coroutines now code like this
 
Public void OnButtonClick ()
{
String videourl="";
StartCoroutine (downloadVideo (videourl));
}

 
IEnumerator downloadVideo (string videourl)
{
WWW WWW=new WWW (videourl);
Yield return WWW.
If (www.isDone)
{
//download video to the video format: mp4)
//Application. The persistentData path

}
}

Can put receives an array of bytes by www.bytes into not memory literatures to local and then in the play?
 
MemoryStream ms=new MemoryStream (www.bytes);
FileStream fs=new FileStream (Application. PersistentData, FileMode. CreateNew);
StreamWriter sw=new StreamWriter (ms);
Sw. WriteTo (fs);
Ms. Close ();
Fs. The Close ();
Sw. The Close ();

In this way, ok?

CodePudding user response:

Struggle for two days finally found the way is to receive a byte array into a file stream it is ok to deposit to the local specific code below
 
FileStream fs=new FileStream (Application. PersistentData, FileMode. Creat, FileAccess. Write);
Fs. Write (www.bytes, 0, www.bytes.length).
Fs. The Close ();


Is the above three sentences code can be so simple I struggled for two days the reason or solid basic skills is not the basic flow operating all don't know
  • Related