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;
    }


}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM