Quantcast
Channel: Questions in topic: "streamingassets"
Viewing all 285 articles
Browse latest View live

How to open a pdf on android device from streaming assets folder

$
0
0
Hi, I've been banging my head against the wall trying to figure this out. I've scoured the forums and have implemented what I think is the correct solution, but it is still not working. I'm trying open a pdf in the device's web browser. The PDF is located in my streaming assets folder. I'm calling the following from OnGUI when a button is pressed. string path; //set the correct path to the rules files if (Application.platform == RuntimePlatform.Android) { path = System.IO.Path.Combine(Application.streamingAssetsPath, Tag.rulesFilename); WWW www = new WWW(path); while (!www.isDone) { //I will replac e this with a Coroutine once its working Debug.Log ("LOADING FILE: " + www.progress); //returns 0 for a few iterations }; Debug.Log ("FILE LOADED: " + www.progress); //returns 1 Debug.Log ("FILE EXISTS: " + (System.IO.File.Exists(path)?"YES":"NO")); //returns NO Debug.Log("ANDROID PATH " + path); //returns ANDROID PATH jar:file:///mnt/asec/com.me.app-1/pkg.apk!/assets/file.pdf Application.OpenURL(www.url); //intent launches but nothing happens } else { path = System.IO.Path.Combine(Application.streamingAssetsPath, Tag.rulesFilename); Application.OpenURL(path); } The non-android portion works fine in the editor and a standalone windows exe. I've also check that the following will open a web browser on android. Application.OpenURL("www.google.com"); Anyone have any ideas? Thanks

StreamingAssets + WWW url not found

$
0
0
Greetings. After muddling through the plethora of other answers on this subject none of their solutions seem to work for me. Here is my situation: I put an assetbundle into my StreamingAssets folder called bundle.unity3d I create a build and look in the build folder and notice that my bundle exists at my.app/Data/Raw/bundle.unity3d I build the xcode project and upload it to the device. When the app starts I run a small script on the camera to tell me which files are on the device and their location. Then I run this code: www = new WWW(System.Uri.EscapeUriString("file:/" + System.IO.Path.Combine(Application.streamingAssetsPath, "bundle.unity3d"))); I end up with a url something like this: file://var/mobile/Applications/{GUID}/my.app/Data/Raw/bundle.unity3d which is completely identical to what the file listing script is telling me (minus the file://) However this will always return with the error "The requested URL was not found on this server." Here is a list of thing's I've tried: Escaping the Uri string because I've heard you MUST do this on iOS. using System.IO.Path.Combine to create the url. Making sure there are no typos. Making sure the file is actually on the device. Use LoadFromCacheOrDownload (this gives the same "url not found" error). What I want to know is: What is the PROPER way to include an asset bundle in your iOS build and then uncompress/load it's contents at runtime. Obviously I'm missing something important here. What is it?

loading video texture from streaming assets

$
0
0
I want to load a video texture from streaming assets so that I can trade out the video file manually without having to recompile. I have a file in streaming assets called 1.mov. Should my c# look something like this:? using UnityEngine; using System.Collections; public class video : MonoBehaviour { public MovieTexture movie; // Use this for initialization void Start () { string movieTexturePath =Application.streamingAssetsPath + "/1.mov"; movie = (MovieTexture)Resources.Load (movieTexturePath, typeof(MovieTexture)); renderer.material.mainTexture = movie as MovieTexture; movie.loop = true; movie.Play (); } }

Editing a script

$
0
0
I've got the following script which extracts files in a string from the streaming assets folder, and saves them to a persistent data path: using UnityEngine; using System.Collections; using System.IO; public class ObbExtractor : MonoBehaviour { void Start () { StartCoroutine(ExtractObbDatasets()); } private IEnumerator ExtractObbDatasets () { string[] filesInOBB = {"Tracker_Name.dat", "Tracker_Name.xml"}; foreach (var filename in filesInOBB) { string uri = "file://" + Application.streamingAssetsPath + "/QCAR/" + filename; string outputFilePath = Application.persistentDataPath + "/QCAR/" + filename; if(!Directory.Exists(Path.GetDirectoryName(outputFilePath))) Directory.CreateDirectory(Path.GetDirectoryName(outputFilePath)); var www = new WWW(uri); yield return www; Save(www, outputFilePath); yield return new WaitForEndOfFrame(); } // When done extracting the datasets, Start Vuforia AR scene } private void Save(WWW www, string outputPath) { File.WriteAllBytes(outputPath, www.bytes); // Verify that the File has been actually stored if(File.Exists(outputPath)) Debug.LogError("File successfully saved at: " + outputPath); else Debug.LogError("Failure!! - File does not exist at: " + outputPath); Application.LoadLevel("SceneMenu1"); } } However, it only saves the .dat file to the path; the first file in the string. So my plan was to identify, extract and save the files individually, as opposed to a string, to see if that worked. I tried this script: using UnityEngine; using System.Collections; using System.IO; public class ObbExtractor2 : MonoBehaviour { void Start () { StartCoroutine(ExtractObbDatasets()); } private IEnumerator ExtractObbDatasets () { string XMLuri = "file://" + Application.streamingAssetsPath + "/QCAR/" + "Tracker_Name.xml"; string XMLoutputFilePath = Application.persistentDataPath + "/QCAR/" + "Tracker_Name.xml"; if(!Directory.Exists(Path.GetDirectoryName(XMLoutputFilePath))) Directory.CreateDirectory(Path.GetDirectoryName(XMLoutputFilePath)); string DATuri = "file://" + Application.streamingAssetsPath + "/QCAR/" + "Tracker_Name.dat"; string DAToutputFilePath = Application.persistentDataPath + "/QCAR/" + "Tracker_Name.dat"; if(!Directory.Exists(Path.GetDirectoryName(DAToutputFilePath))) Directory.CreateDirectory(Path.GetDirectoryName(DAToutputFilePath)); var XMLwww = new WWW(XMLuri); yield return XMLwww; Save(XMLwww, XMLoutputFilePath); yield return new WaitForEndOfFrame(); var DATwww = new WWW(DATuri); yield return DATwww; Save(DATwww, DAToutputFilePath); yield return new WaitForEndOfFrame(); } // When done extracting the datasets, Start Vuforia AR scene private void Save(WWW www, string outputPath) { File.WriteAllBytes(outputPath, www.bytes); // Verify that the File has been actually stored if(File.Exists(outputPath)) Debug.LogError("File successfully saved at: " + outputPath); else Debug.LogError("Failure!! - File does not exist at: " + outputPath); Application.LoadLevel("SceneMenu1"); } } When I test it in the Editor, in the Console it only says the .xml file has been saved (the first one to be identified) Why is it only saved the one file? Could anyone please help?

[help]How can I read the file in StreamingAssets on iPad/iPhone platform???

$
0
0
Hi, When I want to read the local config file, I put the 'a.txt' under 'Assets/StreamingAssets', and read it by WWW class. And the code as follow, WWW www = new WWW("file://" + Application.StreamingAssets + "/a.txt"); This code runs well on PC, Mac Book Pro. But it's wrong on iPhone/iPad. Why ? & How can I read the file under the StreamingAssets folder on iPhone/iPad platform by WWW class? Thank you.

How to load a sprite from streamingassets instead of resources?

$
0
0
UPDATE: No one has any ideas on this one? I would have thought this would be a fairly simple problem to solve. It is a particularly useful thing to be able to do if you want the end-user to be able to easily mod your application with new images ... I'd basically like to do the following: SpriteRenderer sr = myGameObject.GetComponent(); sr.sprite = (Sprite)Resources.Load("mySprite"); ... except, I'd like mySprite to come from the streamingassets directory instead of the Unity resources. Is this possible? Can anyone give me an example of how this is done? Thanks

How to dynamically change a movie texture from Streaming Assets for a windows build

$
0
0
HI, I know there is a lot on the topic out there but I am about to pull my hair out trying to solve this. I need to be able to change movie textures that are stored in the StreamingAssets folder, not the resources folder. I have achieved this using the resources folder but my videos need to be in the StreamingAssets folder as they will change over time. I have also tried the www class with no luck. Any Help will be hugely appreciated.

iOS Loading Local PDF/HTML from StreamingAssets

$
0
0
In our standalone build, we use Application.OpenURL to open our local helpsystem (bunch of loose html files) and our training reference system (bunch of loose pdf files). We have now been tasked with putting our application on on iPad and I noticed it doesn't appear we can use OpenURL with assets in StreamingAssets like we can on standalone. After looking at many other posts, it _appears_ (?) we might be able to copy these files from streamingassets to persistentdata and then use Application.OpenURL, but I've yet to get it working. For testing, I have a simple pdf and html file that reside in the root of StreamingAssets and am using the following code to try to open either one. Has anybody gotten this to work? I've seen some say it used to work, but no more... (I'm on Unity 4.6 RC2 and iOS 8.0). With the following code, the files exist in streamingassets, the www1.bytesDownloaded field is correct after getting via WWW, and the files are copied to persistentDataPath correctly. I just can't seem to get the Application.OpenURL to work with either the html or the pdf... I assume I'm supposed to use the file:// protocol schema but maybe this is the issue. Any pointers are greatly appreciated. public IEnumerator LoadLocal() { string fromPath = Application.streamingAssetsPath + "/"; string toPath = Application.persistentDataPath + "/"; string pdfToLoad = "simple.pdf"; string htmlToLoad = "simplehtml.html"; if(File.Exists(fromPath + pdfToLoad)) { UnityEngine.Debug.Log(string.Format("Sees {0} in streamingassets\n", pdfToLoad)); } if(File.Exists(fromPath + htmlToLoad)) { UnityEngine.Debug.Log(string.Format("Sees {0} in streamingassets\n", htmlToLoad)); } WWW www1 = new WWW("file://" + fromPath + pdfToLoad); yield return www1; UnityEngine.Debug.Log("Sees isDone as : " + www1.isDone); UnityEngine.Debug.Log("Sees bytesDownloaded as : " + www1.bytesDownloaded); if (www1.error != null) { UnityEngine.Debug.Log("Error in www\n"); UnityEngine.Debug.Log(www1.error); } File.WriteAllBytes(toPath + pdfToLoad , www1.bytes); UnityEngine.Debug.Log(string.Format("Wrote pdf to {0}\n", toPath + pdfToLoad\n)); if(File.Exists(toPath + pdfToLoad)) { UnityEngine.Debug.Log("Sees pdf in written to persistentdata location\n"); } UnityEngine.Debug.Log("trying to open " + toPath + pdfToLoad); // none of these work, even if I change to http:// when using the htmlToLoad // Application.OpenURL("file://" + toPath + pdfToLoad); // Application.OpenURL("file:///" + toPath + pdfToLoad); // Application.OpenURL("File:///" + toPath + pdfToLoad); } **SOLUTION** It didn't look this was going to be possible or ideal, so the solution for us involved writing native iOS plugins following Unity's docs that used UIWebView (for local html files) and UIDocumentInteractionController (for local pdf files) to view the documents without having to leave the app. We were able to load the files from their respective Application.dataPath + "/Raw" locations.

What video formats can I use loading from the streaming assets folder?

$
0
0
Im am loading files form the Streaming Assets folder dynamically using the WWW class. I have only been successful with the .ovg format. I can't load any mp4 videos. I have tried a lot of different settings but with no luck, I just get a grey screen. Any help will be appreciated. Thanks!

Can't read lines from file by using StreamReader on Android platform

$
0
0
I need to read a text stream by using StreamReader from file on android platform. File is about 100k lines, so even editor is getting stuck if i try to load it all to TextAsset or if i use WWW. I simply need to read that file line by line without loading it all to a string. Then i'll do a tree generation from the lines that i got from the file. (But probably that part doesn't matter, i just need help on file reading part.) I'm giving the code that i wrote down below. It works perfectly on editor, but fails on android. I would be glad if anyone tell me, what am i missing. (ps. english is not my native and this is my first question on the site. so sorry for the any mistakes that i may have done.) private bool Load(string fileName) { try { string line; string path = Application.streamingAssetsPath +"/"; StreamReader theReader = new StreamReader(path + fileName +".txt", Encoding.UTF8); using (theReader) { { line = theReader.ReadLine(); linesRead++; if (line != null) { tree.AddWord(line); } } while (line != null); theReader.Close(); return true; } } catch (IOException e) { Debug.Log("{0}\n" + e.Message); exception = e.Message; return false; } }

Read XML with XDocument on Windows Phone build at StreamingAssets Folder

$
0
0
Hi i currently have some problem about reading xml. i have XML files at my streamingassets folder. when i load it from editor with application.streamingassetspath + "/Dialog.xml" , and pass it to XDocument.Load parameter it works perfect. but when i build it to android or windows phone it cant find the path... so what i do wrong ? im so frustated, i can load xml file content with www.text, but XDocument.Load need a path not the content :s btw this is my script, i get parameter xmlPath from application.streamingassetspath + "/Dialog.xml" private string RequestDataFromXML(string xmlPath, string mainXmlTag, string id, string requestedAttribute) { string dataFromXML = ""; #if UNITY_ANDROID //_dialogPath = "jar:file://" + Application.dataPath + "!/assets/Pattimura/Dialog.xml"; #endif XDocument xml = XDocument.Load(xmlPath); var queryIntro = from c in xml.Root.Descendants(mainXmlTag) where c.Attribute("id").Value == id select c.Attribute(requestedAttribute).Value; foreach(string text in queryIntro) dataFromXML = text; return dataFromXML; }

Not able to play movie from streaming assets (Prime 31 Etcetera Plugin) Obb Split

$
0
0
I am using prime 31 etcetera plugin to play video , the video is saved in streaming assets folder . The video works fine .But as my apk size is more than 50 mb ,I have to go for a split apk option . Now what happens is the streaming assets video gets copied into the obb and not in the apk. Due to which the video path cannot be found .And prime 31 plugin is not able to play the video. Please help...Thanks in Advance :)

Using WWW to load all files in StreamingAssets directory

$
0
0
Is it possible to use WWW to load any and all files in a given directory within StreamingAssets, or do I have to know the explicit name of every file I'm looking to load? For examaple, "StreamingAssets/" contains a list of .xml files of arbitrary file names "dataSet01.xml", "saveFile-3.xml", "character_data_set_17.xml", so on, and I need to load them all at runtime.

How to read xml file on Android using www and StreamingAssets?

$
0
0
For my Android game, I'm trying to read (and eventually write) to xml file. To do that, I'm using a StreamingAssets folder that I created in the Assets folder. The main source of information are those from Unity doc: [http://docs.unity3d.com/Documentation/Manual/StreamingAssets.html][1] [http://docs.unity3d.com/Documentation/ScriptReference/WWW.html][2] I tried many different paths and setting (External SDCard and Internal Only). I searched a lot for solution, but without success. On my Android Nexus 7 tablet in my try catch I get: System.Xml.XmlException: Document element did not appear. Line 1, position1. Line 1 of my xml file is the basic xml version="1.0" encoding="ISO-8859-15". If I change the file name to something inexistent, I get the same exception. This is my current cleaned code: //OurText inherits from MonoBehaviour. //Text is inherited. public class TextMainMenuLineTwo : OurText { protected override void Start () { base.Start(); StartCoroutine( Init() ); } public IEnumerator Init() { string file; string fileName; WWW www; XmlDocument xmlDocument; file = "Texts.xml"; fileName = "jar:file//" + Application.dataPath + "!/assets/" + file; www = new WWW(fileName); yield return www; xmlDocument = new XmlDocument(); try { xmlDocument.LoadXml(www.text); Text = xmlDocument.SelectSingleNode ("texts/mainMenuTitle").InnerText; } catch(Exception e) { Text = e.ToString(); } } } Thank you all. [1]: http://docs.unity3d.com/Documentation/Manual/StreamingAssets.html [2]: http://docs.unity3d.com/Documentation/ScriptReference/WWW.html

Why unity don't copies the videos to Ipad?

$
0
0
Hi, I been created to StreamingAssets folder, folder, and then, I created a Videos folder, inside the Videos folder insert 2 videos in m4v format. I called this way the videos into the script string pathVideo ="/Videos/video1.m4v"; Debug.Log("FILE " + pathVideo + " EXIST? == " +System.IO.File.Exists(pathVideo)); Handheld.PlayFullScreenMovie (project.videoURL , Color.black,FullScreenMovieControlMode.Full,FullScreenMovieScalingMode.AspectFit); When I builded the project in xcode project, not exist a folder Videos, I create referencing videos folder, but the "Debug.Log" I put before always shows me "FILE /Videos/video1.m4v EXIST? == FALSE", I dont understand what's wrong, because I don't moved something. I just changed the videos to others in best quality, but all videos fail now

iOS won't load streaming asset

$
0
0
Hello, I'm having a bit of trouble loading a file from the StreamingAssets folder on iOS. I have an asset named 'level2a' located in Assets/StreamingAssets. All I am doing is: var path = new GoSpline( "level2a" ); I get a runtime error on the iOS device telling me that the file could not be found at "xxx/xxx/xxx/Data/Raw/level2a". This works perfectly fine in the editor. I have also tried: var path = new GoSpline( Path.Combine(Application.streamingAssetsPath, "level2a")); and I get the same error. Anyone have any idea what's going on here and how to get this to work? Thanks!

How to load an image at runtime via WWW correctly

$
0
0
Hello everyone, I have an image in my Streaming Assets folder that I want to load at run-time and use as a texture. However, when I attempt to do this, I get an error that reads: > You are trying to load data from a www> stream which had the following error> when downloading. Could not resolve> host: C; No data record of requested> type Here is the code that is throwing the error. Any help would be greatly appreciated. Texture2D imageTexture; var path = System.IO.Path.Combine(Application.streamingAssetsPath,"image.png"); Debug.LogError(path); WWW www = new WWW (path); yield return www; imageTexture = www.texture;

How I can use StreamingAssets on Windows Phone?

$
0
0
I need load textures from local storage via WWW. How can I do this?

Cant get streaming assets folder to work with the www class

$
0
0
Hello Unity peeps, So i keep getting the following error with my code: You are trying to load data from a www stream which had the following error when downloading. malformed And heres my code: string url = Application.streamingAssetsPath + "/" + textureName; WWW www = new WWW(url); yield return www; gameObject.renderer.material.mainTexture = www.texture; //error points to this line It works fine if i use a http address for the url which makes me think i might using it wrong but from reading the docs i thought this was okay?!?! Anywho any help would be great, im using unity 3.5.7, on a mac building for iOS and Android.

read write xml file on ipad ,Access denied

$
0
0
i want to save player information to xml file ,but something is wroing , i need your help this is the error information: UnauthorizedAccessException: Access to the path "/var/mobile/Applications/76720F65-B39A-4D02-934D-6CBD9E455B3A/bodhirun.app/Data/Raw/Collection/MyCollections.xml" is denied. at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) [0x00000] in :0 at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share) [0x00000] in :0 at System.Xml.XmlTextWriter..ctor (System.String filename, System.Text.Encoding encoding) [0x00000] in :0 at System.Xml.XmlDocument.Save (System.String filename) [0x00000] in :0 at CollectionControl.SaveCollectionItem (System.String itemType, Int32 itemID) [0x00000] in :0 at CollectionControl.Update () [0x00000] in :0 this is my code: string filepath = Application.streamingAssetsPath + "/Collection/MyCollections.xml"; XmlDocument xmlDoc = new XmlDocument(); if( File.Exists(filepath) ) { xmlDoc.Load (filepath); XmlElement root = (XmlElement)xmlDoc.SelectSingleNode("Collections"); bool isNewElement = true; foreach (XmlElement xe in root.ChildNodes) { int id = int.Parse(xe.InnerText.Split('_')[1]); string type = xe.InnerText.Split ('_')[0]; if(itemType == type && id == itemID) { isNewElement = false; int num = int.Parse(xe.InnerText.Split ('_')[2]) + 1; xe.InnerText = type + "_" + itemID.ToString() + "_" + num.ToString(); } } if( isNewElement ) { XmlElement new_collection = xmlDoc.CreateElement ("item"); new_collection.InnerText = itemType + "_" + itemID.ToString() + "_1"; root.AppendChild(new_collection); } } else { XmlElement root = xmlDoc.CreateElement ("Collections"); XmlElement new_collection = xmlDoc.CreateElement ("item"); new_collection.InnerText = itemType + "_" + itemID.ToString() + "_1"; root.AppendChild(new_collection); xmlDoc.AppendChild(root); } xmlDoc.Save(filepath);
Viewing all 285 articles
Browse latest View live