Skip to content

Commit

Permalink
hammering at the seek logic for the example
Browse files Browse the repository at this point in the history
  • Loading branch information
cbaggers committed Jun 19, 2017
1 parent 3848196 commit 5f8d363
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 10 deletions.
23 changes: 15 additions & 8 deletions Examples/Basics/PlayPage.ux
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,21 @@
</Each>
</StackPanel>
</ScrollView>
<StackPanel Orientation="Horizontal" Dock="Bottom" ItemSpacing="40" ContentAlignment="Center"
Padding="20">
<TextButton Value="Backward" Clicked="{backwardClicked}" />
<TextButton Value="Prev" Clicked="{prevClicked}" />
<TextButton Value="Stop" Clicked="{backClicked}" />
<TextButton Value="Play" Clicked="{playClicked}" />
<TextButton Value="Next" Clicked="{nextClicked}" />
<TextButton Value="Forward" Clicked="{forwardClicked}" />
<StackPanel Orientation="Vertical" Dock="Bottom">
<SeekBar Height="50">
<DockPanel Dock="Bottom">
<Text Value="{progress}" Color="Black"/>
<Text Value="{duration}" Dock="Right" Color="Black" Opacity="0.6"/>
</DockPanel>
</SeekBar>
<StackPanel Orientation="Horizontal" ItemSpacing="40" ContentAlignment="Center" Padding="20">
<TextButton Value="Backward" Clicked="{backwardClicked}" />
<TextButton Value="Prev" Clicked="{prevClicked}" />
<TextButton Value="Stop" Clicked="{backClicked}" />
<TextButton Value="Play" Clicked="{playClicked}" />
<TextButton Value="Next" Clicked="{nextClicked}" />
<TextButton Value="Forward" Clicked="{forwardClicked}" />
</StackPanel>
</StackPanel>
<BottomBarBackground Dock="Bottom" />
</DockPanel>
Expand Down
79 changes: 79 additions & 0 deletions Examples/Basics/SeekBar.js
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
};
23 changes: 23 additions & 0 deletions Examples/Basics/SeekBar.ux
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>
2 changes: 2 additions & 0 deletions src/Android/StreamingAudioService.java
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,8 @@ private void Stop()
// {TODO} why stop the service?
Intent intent = new Intent(getApplicationContext(), StreamingAudioService.class);
stopService(intent);
//
MakeTrackCurrentByUID(-1);
}

//
Expand Down
4 changes: 2 additions & 2 deletions src/iOS/LockScreenControls.uno
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ namespace StreamingPlayer


MPRemoteCommandCenter *commandCenter = [MPRemoteCommandCenter sharedCommandCenter];
NSOperatingSystemVersion ios9_0_0 = (NSOperatingSystemVersion){9, 0, 0};
NSOperatingSystemVersion ios9_0_1 = (NSOperatingSystemVersion){9, 0, 1};

[commandCenter.playCommand addTargetWithHandler:^MPRemoteCommandHandlerStatus(MPRemoteCommandEvent *event) {
play();
Expand All @@ -136,7 +136,7 @@ namespace StreamingPlayer
return MPRemoteCommandHandlerStatusSuccess;
}];

if ([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:ios9_0_0])
if ([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:ios9_0_1])
{
[commandCenter.changePlaybackPositionCommand setEnabled:true];
[commandCenter.changePlaybackPositionCommand addTargetWithHandler:^(MPRemoteCommandEvent *event) {
Expand Down
1 change: 1 addition & 0 deletions src/iOS/StreamingPlayeriOSImpl.uno
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ namespace StreamingPlayer
Status = PlayerStatus.Stopped;
_internalState = iOSPlayerState.Unknown;
_player = null;
MakeTrackCurrentByUID(-1);
}
}

Expand Down

0 comments on commit 5f8d363

Please sign in to comment.