美文网首页Unity3dUnity技术分享Unity教程合集
unity www读取本地视频和外部视频

unity www读取本地视频和外部视频

作者: OneMore2018 | 来源:发表于2017-05-04 11:10 被阅读1414次

    using System.Runtime.InteropServices;
    using UnityEngine;
    using System.Collections;
    using Assets;

    public class PlayVideo : MonoBehaviour
    {
    public string url;
    public MovieTexture movieTexture;
    public WWW www;
    void Start()
    {
    url = "file:///D:/video/sample.ogg";//本地视频
    // url = "http://www.unity3d.com/webplayers/Movie/sample.ogg ";//外部视频
    StartCoroutine(DownLoadMovie());

    }  
    
    private IEnumerator DownLoadMovie()  
    {  
        www = new WWW(url);  
        Debug.Log(Time.time);    
        movieTexture = www.movie;  
        audio.clip = movieTexture.audioClip;  
        renderer.material.mainTexture = movieTexture;  
        movieTexture.loop = true;  
        yield return www;  
          
    
    }  
    
    void Update()  
    {  
    
          Debug.Log("movieTexture.isReadyToPlay" + "     " + movieTexture.isReadyToPlay);  
          Debug.Log("www.isDone" + "     " + www.isDone);  
          Debug.Log("movieTexture.duration" + "     " + movieTexture.duration);  
          Debug.Log("movieTexture.isPlaying" +"      "+ movieTexture.isPlaying);  
    }  
    
    void OnGUI()  
    {  
        if (GUILayout.Button("播放/继续"))  
        {  
            //播放/继续播放视频    
            if (!movieTexture.isPlaying)  
            {  
                movieTexture.Play();  
                audio.Play();  
            }  
        }  
    
        if (GUILayout.Button("暂停播放"))  
        {  
            //暂停播放    
            movieTexture.Pause();  
            audio.Pause();  
        }  
    
        if (GUILayout.Button("停止播放"))  
        {  
            //停止播放    
            movieTexture.Stop();  
            audio.Stop();  
        }    
    }    
    

    }

    相关文章

      网友评论

      • 梦幻碟影:博主,这个只能播放ogg格式的吗,我的mov的播放不出来啊
      • _zoro:在5.6下using Assets会报错。audio.XX也没办法了,楼主已经解决了么
        Zccc_b2f7:@吕一帆呦 如何实现 边下载边 播放 的功能 ? pc端
        OneMore2018:我没有试哎,不过5.6不是有VideoaPlayer组件吗 ,可以试试这个

      本文标题:unity www读取本地视频和外部视频

      本文链接:https://www.haomeiwen.com/subject/esprtxtx.html