Commit cd08c48b authored by Martin Finkel's avatar Martin Finkel
Browse files

remove time display, simplify plugin script

parent af3b7336
using UnityEngine;
using UnityEngine.UI;
using System;
using System.Collections;
using System.Runtime.InteropServices;
public class RemoteTimeDisplayer : MonoBehaviour
{
public Text txt;
string length;
bool playing;
public void
setPlaying (bool state) {
playing = state;
}
string
formatMsToStr (int ms)
{
TimeSpan t = TimeSpan.FromMilliseconds (ms);
string formattedTime = t.Minutes + " : " + t.Seconds;
if (t.Hours > 0)
formattedTime = t.Hours + "h " + formattedTime;
return formattedTime;
}
void
Start ()
{
// Get text object to update
txt = GetComponent<Text> ();
length = formatMsToStr (0);
}
void
Update ()
{
if (!playing)
return;
// We may not receive length the first time
if (length == formatMsToStr (0)) {
// FIXME
// length = formatMsToStr (UseRenderingPlugin.getLengthVLC ());
}
// Format actual time and concate it to length
// FIXME
// string pos = formatMsToStr (UseRenderingPlugin.getTimeVLC ());
// FIXME
//txt.text = pos + "\n" + length;
}
}
......@@ -2,53 +2,41 @@
using System;
using System.Collections;
using LibVLCSharp.Shared;
using System.Runtime.InteropServices;
public class UseRenderingPlugin : MonoBehaviour
{
#if (UNITY_IPHONE || UNITY_WEBGL) && !UNITY_EDITOR
private const string dllname = "__Internal";
#else
private const string dllname = "VlcUnityWrapper";
#endif
LibVLC LibVLC { get; set; }
MediaPlayer MediaPlayer { get; set; }
int seekTimeDelta = 2000;
Texture2D tex = null;
private LibVLC LibVLC { get; set; }
private MediaPlayer MediaPlayer { get; set; }
void Awake()
{
Core.Initialize(Application.dataPath);
// Native plugin rendering events are only called if a plugin is used
// by some script. This means we have to DllImport at least
// one function in some active script.
// For this example, we'll call into plugin's SetTimeFromUnity
// function and pass the current time so the plugin can animate.
LibVLC = new LibVLC("--verbose=2");
// Menu to select video
public GameObject menuVideoSelector;
public RemoteTimeDisplayer rtd;
MediaPlayer = new MediaPlayer(LibVLC);
public int seekTimeDelta = 2000;
MediaPlayer.Play(new Media(LibVLC, "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4", FromType.FromLocation));
private Texture2D tex = null;
StartCoroutine("CallPluginAtEndOfFrames");
}
void Awake()
public void seekForward()
{
SetPluginPath(Application.dataPath);
InitLibVLC(); // slow
Debug.Log("[VLC] Seeking forward !");
MediaPlayer.Time += seekTimeDelta;
}
void InitLibVLC()
public void seekBackward()
{
try
{
Core.Initialize($"{Application.dataPath}\\Plugins");
LibVLC = new LibVLC("--verbose=2");
}
catch (Exception ex)
{
Debug.Log(ex);
}
Debug.Log("[VLC] Seeking backward !");
MediaPlayer.Time -= seekTimeDelta;
}
void OnDisable() {
void OnDisable()
{
MediaPlayer?.Stop();
MediaPlayer?.Dispose();
MediaPlayer = null;
......@@ -57,51 +45,6 @@ void InitLibVLC()
LibVLC = null;
}
[DllImport("RenderingPlugin")]
static extern void Print(string toPrint);
[DllImport("RenderingPlugin")]
static extern void SetPluginPath(string path);
public void OnMenuClick (int index)
{
string movieURL;
switch (index) {
case 1:
string text = UniClipboard.GetText ();
Uri uri = new Uri (text);
if ( uri.IsWellFormedOriginalString() )
movieURL = text;
else
return;
break;
case 2:
movieURL = Constants.Movie480p;
break;
case 3:
movieURL = Constants.Movie1080p;
break;
case 4:
default:
movieURL = Constants.Movie2160p;
break;
}
menuVideoSelector.SetActive (false);
if (MediaPlayer == null)
{
MediaPlayer = new MediaPlayer(LibVLC);
}
var r = MediaPlayer.Play(new Media(LibVLC, "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4", FromType.FromLocation));
// MediaPlayer.Play(new Media(LibVLC, movieURL, FromType.FromLocation));
Debug.Log(r ? "Play successful" : "Play NOT successful");
StartCoroutine("CallPluginAtEndOfFrames");
}
public void playPause()
{
Debug.Log ("[VLC] Toggling Play Pause !");
......@@ -114,31 +57,14 @@ public void playPause()
public void stop ()
{
Debug.Log ("[VLC] Stopping Player !");
rtd.setPlaying (false);
StopCoroutine ("CallPluginAtEndOfFrames");
MediaPlayer?.Stop();
tex = null;
GetComponent<Renderer> ().material.mainTexture = null;
menuVideoSelector.SetActive (true);
}
public void seekForward()
{
Debug.Log ("[VLC] Seeking forward !");
MediaPlayer.Time += seekTimeDelta;
}
public void seekBackward()
{
Debug.Log ("[VLC] Seeking backward !");
MediaPlayer.Time -= seekTimeDelta;
}
void Start()
{
#if UNITY_WEBGL && !UNITY_EDITOR
RegisterPlugin();
#endif
Vector3 scale = transform.localScale;
scale.x = -scale.x;
transform.localScale = scale;
......@@ -159,7 +85,7 @@ private IEnumerator CallPluginAtEndOfFrames()
uint i_videoWidth = 0;
MediaPlayer.Size(0, ref i_videoWidth, ref i_videoHeight);
IntPtr texptr = MediaPlayer.GetFrame(out bool updated);
IntPtr texptr = MediaPlayer.GetTexture(out bool updated);
if (i_videoWidth != 0 && i_videoHeight != 0 && updated && texptr != IntPtr.Zero)
{
Debug.Log("Creating texture with height " + i_videoHeight + " and width " + i_videoWidth);
......@@ -176,7 +102,7 @@ private IEnumerator CallPluginAtEndOfFrames()
}
else if (tex != null)
{
IntPtr texptr = MediaPlayer.GetFrame(out bool updated);
IntPtr texptr = MediaPlayer.GetTexture(out bool updated);
if (updated)
{
tex.UpdateExternalTexture(texptr);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment