码迷,mamicode.com
首页 > 编程语言 > 详细

unity 播放视频 WWW下载StreamingAssets文件

时间:2017-08-21 14:52:21      阅读:1112      评论:0      收藏:0      [点我收藏+]

标签:alt   ios   set   getc   als   component   this   模式   ges   

1.

技术分享

 

2.

技术分享

 

3.

技术分享

4.

技术分享

 

5.

技术分享

6.代码如下

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class test : MonoBehaviour
{
public MovieTexture kk;
bool stopflag = false;
AudioClip _clip;
AudioSource _source;
// Use this for initialization
void Start()
{
//var _movie=Resources.Load<MovieTexture>("movie/movie");
//设置当前对象的主纹理为电影纹理
transform.GetComponent<Renderer>().material.mainTexture = kk;
//设置电影纹理播放模式为循环
kk.loop = true;
_source = Camera.main.GetComponent<AudioSource>();
_clip = kk.audioClip;
GameObject.Find("Playbtn").GetComponent<Button>().onClick.AddListener(() =>
{
kk.Play();
if(stopflag)
{
_source.Play();
}
});
GameObject.Find("Pausebtn").GetComponent<Button>().onClick.AddListener(() =>
{
kk.Pause();
});
GameObject.Find("Stopbtn").GetComponent<Button>().onClick.AddListener(() =>
{
kk.Stop();
stopflag = true;
});
}

// Update is called once per frame
void Update()
{

}
}

7.我希望可以动态加载音频文件,而不是拖动的

技术分享

 

8.代码如下

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class test : MonoBehaviour
{
//public MovieTexture kk;
bool stopflag = false;
AudioClip _clip;
AudioSource _source;
// Use this for initialization
void Start()
{
var kk = Resources.Load<MovieTexture>("movie/movie");
//设置当前对象的主纹理为电影纹理
transform.GetComponent<Renderer>().material.mainTexture = kk;
//设置电影纹理播放模式为循环
kk.loop = true;
_source = Camera.main.GetComponent<AudioSource>();
_clip = kk.audioClip;
_source.clip = _clip;
GameObject.Find("Playbtn").GetComponent<Button>().onClick.AddListener(() =>
{
kk.Play();
_source.Play();
if (stopflag)
{
stopflag = false;
_source.Play();
}
});
GameObject.Find("Pausebtn").GetComponent<Button>().onClick.AddListener(() =>
{
kk.Pause();
});
GameObject.Find("Stopbtn").GetComponent<Button>().onClick.AddListener(() =>
{
kk.Stop();
stopflag = true;
});
}

// Update is called once per frame
void Update()
{

}
}

9.

技术分享

 技术分享

10.WWW加载StreamingAssets的文件

技术分享

 

技术分享

 

11.全部代码

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class test : MonoBehaviour
{
bool stopflag = false;
AudioClip _clip;
AudioSource _source;
WWW www;
private MovieTexture kk;
// Use this for initialization
void Start()
{
StartCoroutine(Down());//异步操作
GameObject.Find("Playbtn").GetComponent<Button>().onClick.AddListener(() =>
{
kk.Play();
_source.Play();
if (stopflag)
{
stopflag = false;
_source.Play();
}
});
GameObject.Find("Pausebtn").GetComponent<Button>().onClick.AddListener(() =>
{
kk.Pause();
});
GameObject.Find("Stopbtn").GetComponent<Button>().onClick.AddListener(() =>
{
kk.Stop();
stopflag = true;
});
}

IEnumerator Down()//异步操作
{
www = new WWW("file:///" + Application.streamingAssetsPath + "/movie.ogg");
yield return www;//等待,知道www把资源下载完,执行下一步
if (string.IsNullOrEmpty(www.error))
{
Debug.LogError("错误为NULL!");
}
if(www.error=="")
{
Debug.LogError("错误为空!");//这个没进来
}
if (www.error == null)
{
Debug.LogError("错误为null");
}
if (www.isDone)
{
Debug.LogError("down");
}
Debug.LogError(www.error);
kk = www.movie;
//设置当前对象的主纹理为电影纹理
transform.GetComponent<Renderer>().material.mainTexture = kk;
//设置电影纹理播放模式为循环
kk.loop = true;
_source = Camera.main.GetComponent<AudioSource>();
_clip = kk.audioClip;
_source.clip = _clip;
}

// Update is called once per frame
void Update()
{

}
}

 

unity 播放视频 WWW下载StreamingAssets文件

标签:alt   ios   set   getc   als   component   this   模式   ges   

原文地址:http://www.cnblogs.com/Study02/p/7404069.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!