• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Catlard · Nov 25, 2013 at 09:18 AM · androidmobilevideostreamingassets

StreamingAssets on Android.

Hey...so...my goal is the following:

  1. Download an .mp4 video with an http request.

  2. Put it in the StreamingAssets folder in my Android APK, using www.bytes and File.WriteAllBytes().

  3. Play it, using the EasyMovieTexture plugin I bought.

However, I'm getting errors when I try to write to the StreamingAssets folder, at the following path:

 jar:file:///data/app/com.catlard.testName-1.apk!/assets/ash.mp4


This is also the first value of _debugString in the PlaceMovieInStreamingAssets function below. Is it even possible to write to the StreamingAssets folder at runtime on Android? Here is the class I'm using to do this stuff. It stops on the WriteAllBytes call -- I know, because I've put print statements before and after, and that's where it's stopping.

 using UnityEngine;
 using System.Collections;
 using System.IO;
 
 public class StartVideoFromWeb : MonoBehaviour {
 
     public string _movieFileName;
     public string _movieHTTPLocation;
     private string _debugString;
     private MediaPlayerCtrl _control;
     public float _mbFileSize = 16.7f;
     private string _movieLocationOnDevice;
 
     private float _prevProg;
 
     private WWW _movieWWW;
 
     public float _kbSpeed;
     public float _timeBetweenSpeedMeasurements = 1f;
 
     // Use this for initialization
 
     public IEnumerator Start() {
 
         yield return StartCoroutine("LoadMovie");
         PlaceMovieInStreamingAssets(_movieWWW);
         yield return new WaitForSeconds(.5f);
         //PlayMovieInCtrl(_movieHTTPLocation + _movieFileName);
         PlayMovieInCtrl(_movieLocationOnDevice);
 
         yield return 0;
     }
 
     public void PlayMovieInCtrl(string path) {
     
         _control = GetComponent<MediaPlayerCtrl>();
         _debugString = _movieFileName + " was loaded into Ctrl";
         _control.Load(path);
         renderer.material.mainTexture = _control.GetVideoTexture();
         _control.Play();
         _debugString = "Attempted to play movie at " + path  + ".";
     
     }
 
     public void PlaceMovieInStreamingAssets(WWW www) {
 
         _movieLocationOnDevice = "jar:file://" + Application.dataPath + "!/assets/" + _movieFileName;
         //_movieLocationOnDevice =  Application.persistentDataPath + "/" + _movieFileName;
         _debugString = "Failed to write to path: " + _movieLocationOnDevice;
         File.WriteAllBytes(_movieLocationOnDevice, www.bytes);
         _debugString = "Wrote file to StreamingAssets folder.";
     }
     
     public IEnumerator MeasureSpeed() {
         yield return new WaitForSeconds(_timeBetweenSpeedMeasurements);
         float tempMeasure = 0;//((_movieWWW.progress - _prevProg) * (_mbFileSize * 1024f)) * (_timeBetweenSpeedMeasurements /Time.deltaTime);
         _prevProg = _movieWWW.progress;
         if(tempMeasure > 0)
             _kbSpeed = Mathf.RoundToInt(tempMeasure);
         StartCoroutine("MeasureSpeed");
     }
 
     public IEnumerator LoadMovie () {
         string urlString = _movieHTTPLocation + _movieFileName;
         _movieWWW = new WWW(urlString);
         bool isLoaded = false;
         StartCoroutine("MeasureSpeed");
 
         while(!isLoaded && _movieWWW.error == null) {
         
             _debugString = "Movie " + Mathf.RoundToInt(_movieWWW.progress * 100f).ToString() + "%";
 
             if(_kbSpeed > 0)
                 _debugString += " @ " + _kbSpeed.ToString() + "kb/sec";
 
             if(_movieWWW.progress == 1.0)
                 isLoaded = true;
             yield return 0;
         }
         StopCoroutine("MeasureSpeed");
 
         if(_movieWWW.error == null)
             _debugString = "Movie loaded with no errors.";
         else
             _debugString = _movieWWW.error.ToString();
 
     }
 
     public void OnGUI() {
         GUI.Label(new Rect(0,0,700,100), _debugString);
         GUI.Label(new Rect(0,30, 400, 100), "Buffered: " + _control.GetCurrentSeekPercent().ToString());
     }
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Catlard · May 30, 2014 at 09:10 AM

I had success doing this in a different instance, but the situation here was that the plugin I was using didn't work consistently. We eventually ditched it.

http://answers.unity3d.com/questions/717073/sharing-photos-and-other-files-on-android.html

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image V-Jankaitis · May 05, 2015 at 03:43 PM 0
Share

did you menaged to save files to stree$$anonymous$$gassets folder? if yes can you post how?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Knowing the position 1 Answer

onControllerHide() crash 0 Answers

video & mobile 0 Answers

movie texture in mobile devices 3 Answers

How to display a video behind gui on mobile 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges