首页 > 编程语言 > 详细

Unity3D VidoePlayer 加载StreamingAssets下视频

时间:2019-12-20 18:42:32      阅读:403      评论:0      收藏:0      [点我收藏+]

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Video;

public class VideoPlayerControl : MonoBehaviour
{
    public VideoPlayer videoPlayer;
    [SerializeField]
    string format = ".mp4";
    [SerializeField]
    string videoName = "";
    [SerializeField]
    string foldPath;
    [SerializeField]
    RawImage rawImage;


    private void Awake()
    {
        if (!rawImage)
        {
            
        }
    }

    private void Start()
    {
        videoPlayer.url = GetFilePath(foldPath, videoName, format);
        
    }


    private void OnGUI()
    {
        if (GUILayout.Button("Play"))
        {
            videoPlayer.Play();
            rawImage.texture = videoPlayer.texture;
        }
    }


    string GetFilePath(string foldPath, string fileName, string fileFormat = ".mp4")
    {
        string filePath;


#if UNITY_IPHONE
        if (!string.IsNullOrEmpty(foldPath))
        {
            filePath="file://"+Application.dataPath + "/Raw/"+foldPath+"/"+fileName+fileFormat;
        }
        else
        {
            filePath="file://"+Application.dataPath + "/Raw/"+fileName+fileFormat;
        }

#endif 
        if (!string.IsNullOrEmpty(foldPath))
        {
            filePath = Application.dataPath + "/StreamingAssets/" + foldPath + "/" + videoName + fileFormat;
        }
        else
        {
            filePath = Application.dataPath + "/StreamingAssets/" + videoName + fileFormat;
        }


        return filePath;
    }


}

Unity3D VidoePlayer 加载StreamingAssets下视频

原文:https://www.cnblogs.com/WinnerYu/p/12074516.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!