Search Unity

Video How to set url, target texture on a Video Plyer prefab?

Discussion in 'Audio & Video' started by ndmrzk, Nov 25, 2019.

  1. ndmrzk

    ndmrzk

    Joined:
    Jul 25, 2018
    Posts:
    23
    Hi, I'm creating an app that utilizes the plugin UnityNativeGallery. Now, its got a method to get videos from gallery. I want to use the video path of selected video and set it to the url video player prefab. As well, as set its texture (like a thumbnail). I'm not sure how to start this as i've never used Video Player. My current code implementing UnityNativeGallery looks like this:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using UnityEngine.EventSystems;
    6.  
    7. public class ChooseVideo : MonoBehaviour
    8. {
    9.     public Button addNewVideo;
    10.     public GameObject VideoPrefab;
    11.     public List<string> VideoList = new List<string>();
    12.     string videoURL;
    13.  
    14.     // Start is called before the first frame update
    15.     void Start()
    16.     {
    17.         // Pick a video from Gallery/Photos
    18.         PickVideo();
    19.     }
    20.  
    21.     void PickVideo()
    22.     {
    23.         NativeGallery.Permission permission = NativeGallery.GetVideoFromGallery((path) =>
    24.         {
    25.             Debug.Log("Video path: " + path);
    26.             if (path != null)
    27.             {
    28.                 // Play the selected video
    29.                 // Handheld.PlayFullScreenMovie("file: //" + path);
    30.  
    31.                 // Instantiate at position (0, 0, 0) and zero rotation.
    32.                 GameObject newVid = Instantiate(VideoPrefab);
    33.                
    34.                //SetParent of the newPic
    35.                newVid.transform.SetParent(VideosContent.transform);
    36.  
    37.                 //Set to parent center
    38.                 newVid.transform.localPosition = Vector3.zero;
    39.  
    40.                 //Set url to prefab
    41.                
    42.  
    43.                 //Add video paths to a list
    44.                 VideoList.Add(path);
    45.             }
    46.         }, "Select a video");
    47.  
    48.         Debug.Log("Permission result: " + permission);
    49.     }
    50. }
    51.  
     
unityunity