Log in or register to post comments

Download and play the video file

March 30, 2015 - 1:46am #6

Hi, I'm trying to first download a video from a url and then load the video prefab with the downloaded file. I tried below code but after finishing the download it gives an error and gets out of the application. here's my code :

	void OnGUI()
	{
		if(GUI.Button(new Rect(0,0,100,100),"download video"))
		{
			StartCoroutine(download());
		}
	}
	
	IEnumerator download()
	{
		string url = "http://techslides.com/demos/sample-videos/small.mp4";
		www = new WWW(url);
		yield return www;
		string filePath = Application.persistentDataPath + "/vid1.mp4";
		File.WriteAllBytes(filePath,www.bytes);
		video.m_path = filePath;
		if(video.VideoPlayer.Load(video.m_path,VideoPlayerHelper.MediaType.ON_TEXTURE,false,0))
		{
			Debug.Log("loaded the video");
		}
		else
		{
			Debug.Log("unsuccessful loading");
		}
		
	}

 

I'm testing it on Android Nexus 5 , I'll appreciate if anyone can help me with this.

Thanks very much

Download and play the video file

March 31, 2015 - 11:42pm #5

I can download the video file and save it on the device , set the path of video prefab to the downloaded file but it still shows the error icon on the video prefab.

I have seen this is the problem of other users in the forum so I'll appreciate if someone who has done it before help us to do this.

Thanks very much

Download and play the video file

April 2, 2015 - 6:23pm #4

A couple questions:

  • Does the downloaded video file play outside of Unity?
  • If you set Path of downloaded video in Inspector (VideoPlaybackBehaviour), does it work?

* Note: Playback of videos in VideoPlayback sample is not supported in Unity PlayMode.

 

Download and play the video file

April 2, 2015 - 8:33pm #3
Good excuse my ignorance, but where you add the code to download the file, I'm doing a similar project and the purpose is to save a file and then load it on a video asset as a local file.
 
I thank you in advance, greetings

Download and play the video file

April 2, 2015 - 11:18pm #2

Hi dm3d

As you said we can't play video inside unity play mode , I can only check if the path is set inside unity. I test it in my Nexus 5. I download the video write it to a file successfuly and then set the path of the video to the video. This way the video is shown with error icon and I can't play the video.

 

Download and play the video file

April 9, 2015 - 6:51pm #1

Things to check:

  • Verify that downloaded video file can be played back (outside of Unity/Android), and that bytes came across okay and file is not corrupt.
  • Set some breakpoints at place where you assign video in code and use debugger to see where it breaks.

 

Log in or register to post comments