-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hammering at the seek logic for the example
- Loading branch information
Showing
6 changed files
with
122 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
var StreamingPlayer = require("FuseJS/StreamingPlayer"); | ||
var Observable = require('FuseJS/Observable'); | ||
var Timer = require("FuseJS/Timer"); | ||
|
||
//------------------------------- | ||
|
||
var progress = Observable(0.0); | ||
var isInteracting = false; | ||
var duration = Observable(0.0); | ||
var sliderValue = Observable(0.0); | ||
var endInteractionTimeout = null; | ||
var timer = null; | ||
|
||
function deleteTimer(){ | ||
if (timer !== null) | ||
Timer.delete(timer); | ||
} | ||
|
||
function createNewTimer() { | ||
deleteTimer(); | ||
timer = Timer.create(function() { | ||
if (!isInteracting) { | ||
duration.value = StreamingPlayer.duration; | ||
progress.value = StreamingPlayer.progress; | ||
} | ||
}, 100, true); | ||
} | ||
|
||
//------------------------------- | ||
|
||
var interacting = function() { | ||
console.log("interacting"); | ||
if (endInteractionTimeout !== null) { | ||
console.log("interacting: clearTimeout"); | ||
clearTimeout(endInteractionTimeout); | ||
} | ||
isInteracting = true; | ||
}; | ||
|
||
|
||
var seekToSliderValue = function() { | ||
if (isInteracting) { | ||
console.log("seekToSliderValue"); | ||
if (sliderValue.value) | ||
{ | ||
console.log("seekToSliderValue: " + sliderValue.value); | ||
StreamingPlayer.seek(sliderValue.value); | ||
} | ||
endInteractionTimeout = setTimeout(function() { | ||
isInteracting = false; | ||
}, 500); | ||
} | ||
}; | ||
|
||
progress.addSubscriber(function(x) { | ||
if (isInteracting || duration.value==0) | ||
return; | ||
var ret = x.value / duration.value; | ||
console.log("progress callback - progress: " + x.value + "setting slider to: " + ret); | ||
sliderValue.value = ret; | ||
}); | ||
|
||
sliderValue.onValueChanged(function(val) { | ||
if (isInteracting) | ||
{ | ||
var newVal = (val * duration.value); | ||
console.log("slideValue changed: setting progress to " + newVal); | ||
progress.value = newVal; | ||
} | ||
}); | ||
|
||
timer = createNewTimer(); | ||
|
||
module.exports = { | ||
seekToSliderValue : seekToSliderValue, | ||
interacting : interacting, | ||
isInteracting : isInteracting, | ||
sliderValue : sliderValue | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<RangeControl ux:Class="SeekBar" ux:Name="mySlider" HitTestMode="LocalBounds" Height="20" Minimum="0" Maximum="1"> | ||
<DockLayout /> | ||
|
||
<JavaScript File="SeekBar.js" /> | ||
|
||
<LinearRangeBehavior/> | ||
<ProgressAnimation> | ||
<Change thumb.Width="100%"/> | ||
</ProgressAnimation> | ||
|
||
<Panel Height="4"> | ||
<DataBinding Target="mySlider.Value" Key="sliderValue" /> | ||
<Panel ux:Name="thumb" Alignment="Left" Width="0%" Height="4" HitTestMode="LocalBounds"> | ||
<Rectangle CornerRadius="2" Color="Black"/> | ||
</Panel> | ||
<Rectangle Layer="Background" CornerRadius="2" Color="Black" Opacity="0.4"/> | ||
</Panel> | ||
|
||
<WhileInteracting> | ||
<Callback Handler="{interacting}" /> | ||
<Callback Handler="{seekToSliderValue}" Direction="Backward" /> | ||
</WhileInteracting> | ||
</RangeControl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters