- Home /
Error loading video from custom local url and playing it using VideoPlayer component
I am trying to load a video file at runtime and play that video using the Unitys Video player component.The video is located in a folder on the mobile. i receive the URL to the file location(this is tested correct). While looking for the file Unity even finds the file at location but is not able to play it. I receive the following error :
AndroidVideoMedia: Error opening extractor: -10002
There is nothing on the internet regarding this issue as well. One page said something about changing gradle version.
Please note that this works fine on the editor. I have also noticed if putting a file in the persistent data path of the app, then loading and playing is fine. But if the file is kept in any other custom folder, then even after finding the video Unity is not able to play it.
Following is a snippet of the code :
void Start()
{
StartCoroutine("LoadVideoRoutine");
}
IEnumerator LoadVideoRoutine()
{
if(video==null)
yield return null;
string root = _arManager.VideoURLToPlay;
print("This is video url : " + root);
if(!File.Exists(root))
{
print("no video");
yield return null;
}
else if(File.Exists(root))
{
print("Found vid");
video.url = root;
video.Prepare();
// video.Play();
}
while(!video.isPrepared)
{
print("preparing");
yield return null;
}
print("playing");
video.Play();
// video.url = root;
// video.Play();
}
Following is a sample URL where the video is present :
"/storage/emulated/0/MyApp/RaceRecordings/3D2A4AF9-A6EB-4D48-92D2-1B2A6ADC968A.mp4"
In the logs, I got the "Found vid" log indicating that unity finds the file. But immediately when i am setting the url i got the error.
I am not sure what this is and would appreciate some help in this regard. Thank you in advance.
Answer by xxmariofer · Dec 17, 2020 at 09:05 AM
Some notes, you should probably use
yield break;
if no video is found. Also have you tried using the videoclip rather than the url to play the video? change the audiotype if necesary
using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(root, AudioType.OGGVORBIS))
{
yield return www.SendWebRequest();
if (www.result == UnityWebRequest.Result.ConnectionError)
{
Debug.Log(www.error);
}
else
{
AudioClip myClip = DownloadHandlerAudioClip.GetContent(www);
}
}
Your answer
Follow this Question
Related Questions
Is it possible to access a file from the android Internal storage on to a Unity app during run time? 0 Answers
How do you import a unity vr or ar project to android studio to launch as its own activity? 1 Answer
Handheld.PlayFullScreenMovie memory leak? 1 Answer
ARCore for Unity save camera image 1 Answer