当前位置:网站首页>Unity get local video / download network video
Unity get local video / download network video
2022-06-12 15:33:00 【Solitary smoke cold~】
using System.Collections;
using System.IO;
using UnityEngine;
public class DownVideo : MonoBehaviour
{
FileStream fs;
string path = null;
public VideoPlayer video;
void Awake()
{
StartCoroutine(DownOrLoadVideo(" Video name ", "http://kanyikan.oss-cn-shanghai.aliyuncs.com/kanrongmei/%E6%B1%89%E5%85%B3%E7%B4%AB%E7%A0%82.mp4"));
// If the object is hidden Unable to execute the coordination process You can use global inheritance MONO If you call a coroutine with a single column, you won't report an error
//MainController.GetInstance().StartCoroutine(DownOrLoadVideo(" Video name ", "http://kanyikan.oss-cn-shanghai.aliyuncs.com/kanrongmei/%E6%B1%89%E5%85%B3%E7%B4%AB%E7%A0%82.mp4"));
}
/// <summary>
/// Load the video and download
/// </summary>
/// <param name="itm">ImgTargetMgr</param>
/// <param name="downloadVideoName"> Identification drawing name </param>
/// <param name="videoURL"> Video network address </param>
IEnumerator DownOrLoadVideo(string downloadVideoName, string videoURL)
{
#if UNITY_EDITOR
path = Application.dataPath + @"/Video";
#elif UNITY_IPHONE || UNITY_ANDROID
string[] src = new string[1] {
"Android" };
string[] srcs = Application.persistentDataPath.Split(src, System.StringSplitOptions.None);
path = srcs[0] + @"/Video";
#endif
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
Debug.Log(" download " + path);
// Download or not
if (File.Exists(path + @"/" + downloadVideoName + ".mp4"))
{
// Local load
path += "/" + downloadVideoName + ".mp4";
video.url = path ;// Assignment can play
}
else
{
// Network load
WWW www = new WWW(videoURL);
yield return www;
if (!string.IsNullOrEmpty(www.error))
{
Debug.Log(" request was aborted ");
}
else
{
fs = File.Create(path + "/" + downloadVideoName + ".mp4"); //path For the path where you want to save the file .
fs.Write(www.bytes, 0, www.bytes.Length);
fs.Close();
path += "/" + downloadVideoName + ".mp4";
video.url = path ;// Assignment can play
Debug.Log(" Video download successful ");
}
}
}
}
边栏推荐
- How to write year-end summary
- 作業提交說明 上傳作業到網盤中
- Scala download and idea installation of scala plug-ins (nanny level tutorial is super detailed)
- [untitled]
- ssm中的文件上传和下载
- Servlet knowledge explanation (2)
- How to set public IP access on the H3C gr5200 router
- [LDA] basic knowledge notes - mainly AE and VAE
- 虚拟机中用户和root忘记密码解决办法
- First set and follow set in vernacular
猜你喜欢
![[jvm learning] parental delegation mechanism and PC register (program counter)](/img/23/c7b1de7f648716c0f6b615dd22c64d.jpg)
[jvm learning] parental delegation mechanism and PC register (program counter)

Application of postman-rest client plug-in

3D reconstruction system | L3 dual view motion recovery structure (SFM binocular SFM)

Mh32f103arpt6 hardware and software compatible alternative to stm32f103rct6

Preparation of service for robot moving forward and rotating

Understanding of Odom coordinate system

Use of boost:: bind() in ROS

Solve log4j2 vulnerability and be attacked by mining and zombie process viruses

IMU的学习记录

jupyter notebook新環境快捷方式
随机推荐
Codeworks round 797 (Div. 3, cf1690)
Seaborn Brief
IMU learning records
Use and understanding of generics
Deepin20.6 rtx3080 installing graphics card drivers 510.60.02, cuda11.6, pytorch1.11
任务 输出密雪冰城主题曲 0612
3D reconstruction system | L3 incremental motion recovery structure (incremental SFM)
Village to village communication (and collective search)
#include使用“文件名“和<文件名>引入头文件的区别及简述
Remote control of other computers -- detailed tutorial
Design concept of ORM framework
学习是一件逆人性的事情(成为高手的内功心法)
The difference and brief description of "file name" and < file name > import header file used in # include
POSTMAN-REST Client插件的应用
About layoffs in Internet companies
Servlet knowledge explanation (2)
TCP与UDP的区别,以及TCP的三次握手和TCP的四次挥手
Servlet知识详解(2)
分布式并发重复提交问题
RARP总结(TCP/IP详解卷1/2)