- Home /
StreamingAssets on Android.
Hey...so...my goal is the following:
Download an .mp4 video with an http request.
Put it in the StreamingAssets folder in my Android APK, using www.bytes and File.WriteAllBytes().
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());
}
}
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
did you menaged to save files to stree$$anonymous$$gassets folder? if yes can you post how?
Your answer
Follow this Question
Related Questions
Record a video in unity on mobile (Android, IOS) 1 Answer
load video into mobile app 1 Answer
Video to be play in a 360 degree fashion? 2 Answers
Kindle Fire Video Streaming Crash 0 Answers
Streaming assets android 0 Answers