I am trying to create a media player in Unity that reads all media files from a static folder and plays trough all medias (images static duration, videos for the length of the video). First I am trying to get it to work with just images.
I'm very new with Unity and not good with C#. I'm able to get all media file sources (images) to an array but next I need to convert them to a texture and place on the RawImage -component. I'm stuck with this part.
If I have the src (ex. C:mediasimg1.jpg) then how could I place this as a image on the RawImage -component?
My code ->
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEditor;
using System;
using System.IO;
using System.Linq;
public class Player : MonoBehaviour {
// Use this for initialization
void Start () {
DirectoryInfo dir = new DirectoryInfo(@"C:medias");
string[] extensions = new[] { ".jpg", ".JPG", ".jpeg", ".JPEG", ".png", ".PNG", ".ogg", ".OGG" };
FileInfo[] info = dir.GetFiles().Where(f => extensions.Contains(f.Extension.ToLower())).ToArray();
Debug.Log (info[0]);
// Logs C:mediasimg1.jpg
}
// Update is called once per frame
void Update () {
}
}
Thanks :)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…