Skip to content

Commit

Permalink
slidertest: track playing media tracks
Browse files Browse the repository at this point in the history
Since I currently don't get updates on position info within the tracks I
can't update the slider to a new position if I scroll back and forth on
the phone.
  • Loading branch information
thyttan committed Sep 3, 2023
1 parent 954ab81 commit 0e0e874
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions apps/slidertest/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ let callback2 = (mode,fb)=>{
print("#drag handlers: " + Bangle["#ondrag"].length)
};

let currentLevel = 10;

let R = Bangle.appRect;

let draw = (rect)=>{
Expand All @@ -30,21 +28,43 @@ let draw = (rect)=>{
};

let sliderObject2;
let init = ()=> {
draw();
let initSlider2 = ()=>{
sliderObject2 = require("SliderInput").interface(
callback2,
{useMap:true, steps:30, currLevel:currentLevel, horizontal:true, rounded:false, timeout:0, useIncr:false, immediateDraw:false, propagateDrag:true, width:Math.round(Bangle.appRect.w/20), xStart:R.x2-R.w/20-4, oversizeR:10, oversizeL:10, autoProgress:true}
{useMap:true, steps:trackDur, currLevel:trackPosition, horizontal:true, rounded:false, timeout:0, useIncr:false, immediateDraw:false, propagateDrag:true, width:Math.round(Bangle.appRect.w/20), xStart:R.x2-R.w/20-4, oversizeR:10, oversizeL:10, autoProgress:true}
);
sliderObject2.f.draw(sliderObject2.v.level);
sliderObject2.f.startAutoUpdate();
}

let init = ()=> {
draw();
initSlider2();
}

let audioLevels = {u:30, c:15}; // Init with values to avoid "Uncaught Error: Cannot read property 'u' of undefined" if values were not gathered from Gadgetbridge.
let audioHandler = (e)=>{audioLevels = e;};
Bangle.on('audio', audioHandler);
Bangle.musicControl("volumegetlevel");

// Bangle.emit("message", type, msg);
let trackPosition = 0;
let trackDur = 30;
let messageHandler = (type, msg)=>{
print(type, msg);
if (type='music'){

Check warning on line 55 in apps/slidertest/app.js

View workflow job for this annotation

GitHub Actions / build

Expected a conditional expression and instead saw an assignment
trackPosition = 1; // should depend on msg.position or similar.
trackDur = msg.dur;
print('trackPosition: ' + trackPosition)
if (sliderObject2) {
sliderObject2.f.stopAutoUpdate();
sliderObject2.f.remove();
initSlider2();
}
}
}
Bangle.on('message', messageHandler);

init();

let ebLast = 0; // Used for fix/Hack needed because there is a timeout before the slider is called upon.
Expand Down

0 comments on commit 0e0e874

Please sign in to comment.