Skip to content

Commit 1fc9526

Browse files
committed
Release v1.6.0
1 parent 3c0ac5a commit 1fc9526

File tree

8 files changed

+1953
-720
lines changed

8 files changed

+1953
-720
lines changed

Assets/MagicLeap/Examples/Prefabs/MediaPlayer/MediaPlayer.prefab

Lines changed: 1807 additions & 705 deletions
Large diffs are not rendered by default.

Assets/MagicLeap/Examples/Scenes/MediaPlayer.unity

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ RenderSettings:
3838
m_ReflectionIntensity: 1
3939
m_CustomReflection: {fileID: 0}
4040
m_Sun: {fileID: 0}
41-
m_IndirectSpecularColor: {r: 0.18028378, g: 0.22571412, b: 0.30692285, a: 1}
41+
m_IndirectSpecularColor: {r: 0.18028386, g: 0.22571427, b: 0.3069231, a: 1}
4242
m_UseRadianceAmbientProbe: 0
4343
--- !u!157 &3
4444
LightmapSettings:
@@ -266,17 +266,17 @@ PrefabInstance:
266266
- target: {fileID: 9144045079751414315, guid: 6906f74934047d24e9a47bbdd1afb57a,
267267
type: 3}
268268
propertyPath: m_AnchorMax.x
269-
value: 1
269+
value: 0
270270
objectReference: {fileID: 0}
271271
- target: {fileID: 9144045079751414315, guid: 6906f74934047d24e9a47bbdd1afb57a,
272272
type: 3}
273273
propertyPath: m_AnchorMax.y
274-
value: 1
274+
value: 0
275275
objectReference: {fileID: 0}
276276
- target: {fileID: 9144045079751414315, guid: 6906f74934047d24e9a47bbdd1afb57a,
277277
type: 3}
278278
propertyPath: m_AnchorMin.y
279-
value: 0.42647344
279+
value: 0
280280
objectReference: {fileID: 0}
281281
- target: {fileID: 9144045079827347966, guid: 6906f74934047d24e9a47bbdd1afb57a,
282282
type: 3}
@@ -945,11 +945,21 @@ PrefabInstance:
945945
propertyPath: m_RootOrder
946946
value: 9
947947
objectReference: {fileID: 0}
948+
- target: {fileID: 4970164632262232344, guid: 0ffd6c0636c54b94cb445a6bcd349bf1,
949+
type: 3}
950+
propertyPath: m_LocalPosition.z
951+
value: -1
952+
objectReference: {fileID: 0}
948953
- target: {fileID: 4970164632385023829, guid: 0ffd6c0636c54b94cb445a6bcd349bf1,
949954
type: 3}
950955
propertyPath: m_AnchorMax.y
951956
value: 0
952957
objectReference: {fileID: 0}
958+
- target: {fileID: 4970164632476373581, guid: 0ffd6c0636c54b94cb445a6bcd349bf1,
959+
type: 3}
960+
propertyPath: captionsStayDuration
961+
value: 4
962+
objectReference: {fileID: 0}
953963
- target: {fileID: 4970164632542030427, guid: 0ffd6c0636c54b94cb445a6bcd349bf1,
954964
type: 3}
955965
propertyPath: m_RootOrder
@@ -970,11 +980,6 @@ PrefabInstance:
970980
propertyPath: m_Enabled
971981
value: 0
972982
objectReference: {fileID: 0}
973-
- target: {fileID: 6669455948576777451, guid: 0ffd6c0636c54b94cb445a6bcd349bf1,
974-
type: 3}
975-
propertyPath: source
976-
value: http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4
977-
objectReference: {fileID: 0}
978983
m_RemovedComponents: []
979984
m_RemovedGameObjects: []
980985
m_AddedGameObjects: []
@@ -1208,6 +1213,11 @@ PrefabInstance:
12081213
propertyPath: m_AnchorMax.y
12091214
value: 0
12101215
objectReference: {fileID: 0}
1216+
- target: {fileID: 4970164632476373581, guid: 0ffd6c0636c54b94cb445a6bcd349bf1,
1217+
type: 3}
1218+
propertyPath: captionsStayDuration
1219+
value: 4
1220+
objectReference: {fileID: 0}
12111221
- target: {fileID: 6303785438278071680, guid: 0ffd6c0636c54b94cb445a6bcd349bf1,
12121222
type: 3}
12131223
propertyPath: m_Enabled
@@ -1357,6 +1367,11 @@ PrefabInstance:
13571367
propertyPath: m_AnchorMin.x
13581368
value: 0
13591369
objectReference: {fileID: 0}
1370+
- target: {fileID: 4970164632476373581, guid: 0ffd6c0636c54b94cb445a6bcd349bf1,
1371+
type: 3}
1372+
propertyPath: captionsStayDuration
1373+
value: 4
1374+
objectReference: {fileID: 0}
13601375
- target: {fileID: 6303785438278071680, guid: 0ffd6c0636c54b94cb445a6bcd349bf1,
13611376
type: 3}
13621377
propertyPath: m_Enabled

Assets/MagicLeap/Examples/Scripts/MediaPlayer/Controls/MediaPlayerControls.cs

Lines changed: 117 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
// %BANNER_END%
1010

1111
using System;
12+
using System.Collections;
13+
using System.Collections.Generic;
1214
using MagicLeap.Core;
1315
using UnityEngine;
1416
using UnityEngine.UI;
@@ -59,6 +61,21 @@ public class MediaPlayerControls : MonoBehaviour
5961
[SerializeField, Tooltip("Text for captions")]
6062
private Text captionsText = null;
6163

64+
[SerializeField, Tooltip("Dropdown for the language track for captions")]
65+
private Dropdown captionsTracksDropdown = null;
66+
67+
[SerializeField, Tooltip("Duration in seconds to delay before displaying a caption")]
68+
private float captionsDelayDuration = 1;
69+
70+
[SerializeField, Tooltip("Duration in seconds for a caption to stay on screen")]
71+
private float captionsStayDuration = 4;
72+
73+
private IEnumerator captionsCoroutine;
74+
private List<MLMedia.Player.Track> tracks = new List<MLMedia.Player.Track>();
75+
private List<string> trackLanguages = new List<string>();
76+
private MLMedia.Player.Track currentTrack;
77+
private float currentElapsedTimeMS;
78+
6279
void Awake()
6380
{
6481
if (mediaPlayerBehavior == null)
@@ -79,6 +96,37 @@ void OnDisable()
7996
UnregisterCallbacks();
8097
}
8198

99+
public void OnTrackDropdownValueChanged(int value)
100+
{
101+
mediaPlayerBehavior.UnselectTrack(currentTrack);
102+
103+
if (captionsCoroutine != null)
104+
StopCoroutine(captionsCoroutine);
105+
106+
bool wasPlaying = mediaPlayerBehavior.IsPlaying;
107+
108+
// seek current position in the timeline to trigger the track to change if not stopped
109+
if (currentElapsedTimeMS > 0)
110+
{
111+
mediaPlayerBehavior.SeekTo(currentElapsedTimeMS);
112+
113+
// ensure that if it was already paused that it will remain paused
114+
if (!wasPlaying)
115+
{
116+
StartCoroutine(PauseAfterSeeking());
117+
}
118+
}
119+
120+
currentTrack = tracks[value];
121+
mediaPlayerBehavior.SelectTrack(currentTrack);
122+
}
123+
124+
private IEnumerator PauseAfterSeeking()
125+
{
126+
yield return new WaitUntil(() => mediaPlayerBehavior.IsPlaying);
127+
mediaPlayerBehavior.MediaPlayer.Pause();
128+
}
129+
82130
private void RegisterCallbacks()
83131
{
84132
mediaPlayerBehavior.OnPrepared += HandleOnPrepared;
@@ -89,6 +137,7 @@ private void RegisterCallbacks()
89137
mediaPlayerBehavior.OnSeekComplete += HandleOnSeekComplete;
90138
mediaPlayerBehavior.OnCaptionsText += OnCaptionsText;
91139
mediaPlayerBehavior.OnTrackSelected += OnTrackSelected;
140+
mediaPlayerBehavior.OnTrackFound += OnTrackFound;
92141
mediaPlayerBehavior.OnUpdateTimeline += HandleOnTimelineChanged;
93142
mediaPlayerBehavior.OnUpdateElapsedTime += HandleOnElapsedTimeChanged;
94143
mediaPlayerBehavior.OnIsBufferingChanged += HandleOnIsBufferingChanged;
@@ -113,6 +162,7 @@ private void UnregisterCallbacks()
113162
mediaPlayerBehavior.OnSeekComplete -= HandleOnSeekComplete;
114163
mediaPlayerBehavior.OnCaptionsText -= OnCaptionsText;
115164
mediaPlayerBehavior.OnTrackSelected -= OnTrackSelected;
165+
mediaPlayerBehavior.OnTrackFound -= OnTrackFound;
116166
mediaPlayerBehavior.OnUpdateTimeline -= HandleOnTimelineChanged;
117167
mediaPlayerBehavior.OnUpdateElapsedTime -= HandleOnElapsedTimeChanged;
118168
mediaPlayerBehavior.OnIsBufferingChanged -= HandleOnIsBufferingChanged;
@@ -148,6 +198,7 @@ private void PlayPause()
148198
/// </summary>
149199
private void Stop()
150200
{
201+
currentElapsedTimeMS = 0;
151202
mediaPlayerBehavior.StopMLMediaPlayer();
152203
}
153204

@@ -337,12 +388,46 @@ private void HandleOnSeekComplete()
337388
}
338389
}
339390

391+
/// <summary>
392+
/// Callback handler on track found.
393+
/// </summary>
394+
/// <param name="track"></param>
395+
private void OnTrackFound(MLMedia.Player.Track track)
396+
{
397+
if (track.TrackType == MLMedia.Player.Track.Type.TimedText)
398+
{
399+
captionsTracksDropdown.gameObject.SetActive(true);
400+
401+
tracks.Add(track);
402+
string languageType = GetTrackLanguage(track);
403+
trackLanguages.Add(languageType);
404+
captionsTracksDropdown.ClearOptions();
405+
captionsTracksDropdown.AddOptions(trackLanguages);
406+
407+
// default to English when starting
408+
if (trackLanguages.Contains("English"))
409+
captionsTracksDropdown.value = trackLanguages.IndexOf("English");
410+
411+
if (currentTrack == null || track.Language == "en")
412+
{
413+
if (currentTrack != null)
414+
mediaPlayerBehavior.UnselectTrack(currentTrack);
415+
416+
currentTrack = track;
417+
418+
mediaPlayerBehavior.SelectTrack(currentTrack);
419+
}
420+
}
421+
}
422+
340423
/// <summary>
341424
/// Callback handler on track selected.
342425
/// </summary>
343426
/// <param name="track"></param>
344427
void OnTrackSelected(MLMedia.Player.Track track)
345428
{
429+
currentTrack = track;
430+
346431
if (track.TrackType == MLMedia.Player.Track.Type.TimedText || track.TrackType == MLMedia.Player.Track.Type.Subtitle)
347432
captionsText.text = string.Empty;
348433
}
@@ -353,7 +438,11 @@ void OnTrackSelected(MLMedia.Player.Track track)
353438
/// <param name="text"></param>
354439
void OnCaptionsText(string text)
355440
{
356-
captionsText.text = text;
441+
if (captionsCoroutine != null)
442+
StopCoroutine(captionsCoroutine);
443+
444+
captionsCoroutine = DisplayCaption(text);
445+
StartCoroutine(captionsCoroutine);
357446
}
358447

359448
/// <summary>
@@ -362,9 +451,36 @@ void OnCaptionsText(string text)
362451
/// <param name="elapsedTimeMs">Elapsed time in milliseconds</param>
363452
private void UpdateElapsedTime(long elapsedTimeMs)
364453
{
454+
currentElapsedTimeMS = elapsedTimeMs;
455+
365456
TimeSpan timeSpan = new TimeSpan(elapsedTimeMs * TimeSpan.TicksPerMillisecond);
366457
elapsedTime.text = $"{timeSpan.Hours}:{timeSpan.Minutes:00}:{timeSpan.Seconds:00}";
367458
}
459+
460+
461+
private IEnumerator DisplayCaption(string text)
462+
{
463+
yield return new WaitForSeconds(captionsDelayDuration);
464+
captionsText.text = text;
465+
yield return new WaitForSeconds(captionsStayDuration);
466+
captionsText.text = "";
467+
captionsCoroutine = null;
468+
}
469+
470+
private string GetTrackLanguage(MLMedia.Player.Track track)
471+
{
472+
// TODO: Add support for more captions track languages
473+
if (track.Language == "en")
474+
return "English";
475+
else if (track.Language == "es")
476+
return "Español";
477+
else if (track.Language == "fr")
478+
return "Français";
479+
else if (track.Language == "de")
480+
return "Deutsch";
481+
else
482+
return track.Language.ToString();
483+
}
368484
}
369485
}
370486

Assets/MagicLeap/Examples/Scripts/WebViewExample.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ private void OnBumper(InputAction.CallbackContext obj)
136136
}
137137
}
138138

139-
private void OnTabCreated(MLWebViewTabBehavior tab)
139+
private void OnTabCreated(MLWebViewTabBehavior tab, string url = null)
140140
{
141141
tab.WebView.OnLoadEnded += OnLoadEnded;
142142
tab.WebView.OnErrorLoaded += OnErrorLoaded;
@@ -146,7 +146,7 @@ private void OnTabCreated(MLWebViewTabBehavior tab)
146146

147147
tab.OnTabSelected += TabOnOnTabSelected;
148148

149-
tab.GoToUrl(homeUrl);
149+
tab.GoToUrl(url ?? homeUrl);
150150
}
151151

152152
private void TabOnOnTabSelected(MLWebViewTabBehavior obj)
-32 Bytes
Binary file not shown.

Packages/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"com.unity.modules.vehicles": "1.0.0",
3636
"com.unity.modules.video": "1.0.0",
3737
"com.unity.modules.wind": "1.0.0",
38-
"com.magicleap.unitysdk": "1.5.0"
38+
"com.magicleap.unitysdk": "1.6.0"
3939
},
4040
"scopedRegistries": [
4141
{

Packages/packages-lock.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"dependencies": {
33
"com.magicleap.unitysdk": {
4-
"version": "1.5.0",
4+
"version": "1.6.0",
55
"depth": 0,
66
"source": "registry",
77
"dependencies": {

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ The files in this project can change or even be removed from one release to anot
77

88
## Compatible with
99
- Unity Editor 2022.2
10-
- Magic Leap Unity SDK 1.5.0
10+
- Magic Leap Unity SDK 1.6.0
1111

1212
# Copyright
1313
Copyright (c) 2020-present Magic Leap, Inc. All Rights Reserved.

0 commit comments

Comments
 (0)