Skip to content
This repository has been archived by the owner on Mar 11, 2024. It is now read-only.

Commit

Permalink
Seekbar preview (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
Saticmotion authored Mar 27, 2018
1 parent 94349dd commit d890285
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
30 changes: 22 additions & 8 deletions Assets/Scripts/UIScripts/Seekbar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,18 @@ public class Seekbar : MonoBehaviour, IPointerDownHandler
public void Start()
{
curSeekbarHeight = maxSeekbarHeight;

startRotation = 0;
}

public void Update()
{
var coords = new Vector3[4];
seekbarBackground.parent.GetComponent<RectTransform>().GetWorldCorners(coords);
var infoPanelCoords = new Vector3[4];
var seekbarCoords = new Vector3[4];
seekbarBackground.parent.GetComponent<RectTransform>().GetWorldCorners(infoPanelCoords);
seekbarBackground.GetComponent<RectTransform>().GetWorldCorners(seekbarCoords);

hovering = Input.mousePosition.y < coords[1].y;
hovering = Input.mousePosition.y < infoPanelCoords[1].y;
var onSeekbar = Input.mousePosition.y > seekbarCoords[0].y && Input.mousePosition.y < seekbarCoords[1].y;

var newHeight = hovering
? curSeekbarHeight + ((maxSeekbarHeight - minSeekbarHeight) * (Time.deltaTime / seekbarAnimationDuration))
Expand All @@ -46,8 +48,20 @@ public void Update()

lastSmoothTime = float.IsNaN(smoothedTime) ? 0 : smoothedTime;

//TODO(Simon): Maybe make this run less often because it generates garbage
timeText.text = String.Format(" {0} / {1}", MathHelper.FormatSeconds(controller.currentTime), MathHelper.FormatSeconds(controller.videoLength));
if (onSeekbar)
{
var pos = Input.mousePosition.x;
var max = GetComponent<RectTransform>().rect.width;

var time = pos / max;

timeText.text = String.Format(" {0} / {1}", MathHelper.FormatSeconds(controller.TimeForFraction(time)), MathHelper.FormatSeconds(controller.videoLength));
}
else
{
//TODO(Simon): Maybe make this run less often because it generates garbage
timeText.text = String.Format(" {0} / {1}", MathHelper.FormatSeconds(controller.currentTime), MathHelper.FormatSeconds(controller.videoLength));
}

//TODO(Simon): Verify that this works.
if (!UnityEngine.XR.XRSettings.enabled)
Expand All @@ -70,8 +84,8 @@ public void OnPointerDown(PointerEventData e)
var pos = e.pressPosition.x;
var max = GetComponent<RectTransform>().rect.width;

var time = pos / max;
var fractionalTime = pos / max;

controller.Seek(time);
controller.Seek(fractionalTime);
}
}
5 changes: 5 additions & 0 deletions Assets/Scripts/VideoController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ public void Seek(float fractionalTime)
video.time = fractionalTime * videoLength;
}

public double TimeForFraction(float fractionalTime)
{
return fractionalTime * videoLength;
}

public void TogglePlay()
{
if (!playing)
Expand Down

0 comments on commit d890285

Please sign in to comment.