Unity3D VidoePlayer 加载StreamingAssets下视频

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下视频)