unity 播放视频 WWW下载StreamingAssets文件

时间:2017-08-21 14:26:29   收藏:0   阅读:1881

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()
{

}
}

 

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

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!