From a842866dac1a779b769fbaff57617346aef62ed3 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.comā©> Date: Sun, 3 Sep 2023 23:58:49 +0200 Subject: [PATCH] slidertest: track playing media tracks 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. --- apps/slidertest/app.js | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/apps/slidertest/app.js b/apps/slidertest/app.js index a142cd96f92..3d42902f0f7 100644 --- a/apps/slidertest/app.js +++ b/apps/slidertest/app.js @@ -18,8 +18,6 @@ let callback2 = (mode,fb)=>{ print("#drag handlers: " + Bangle["#ondrag"].length) }; -let currentLevel = 10; - let R = Bangle.appRect; let draw = (rect)=>{ @@ -30,14 +28,18 @@ 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. @@ -45,6 +47,24 @@ 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'){ + 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.