How to unmarshal JSON into durations?

The lack of JSON marshaling and unmarshaling methods on time.Duration was an unfortunate oversight. This should hopefully be resolved in Go2 (see issue #10275). You can, however, define your own type around time.Duration that supports marshaling to the string representation of the duration and unmarshaling from either the numeric or string representations. Here is an … Read more

scrollTo speed/duration setting

Live example solution with pure javascript below: /* Effects List: – linearTween – easeInQuad, easeOutQuad, easeInOutQuad – easeInCuaic, easeOutCuaic, easeInOutCuaic – easeInQuart, easeOutQuart, easeInOutQuart – easeInQuint, easeOutQuint, easeInOutQuint – easeInSine, easeOutSine, easeInOutSine – easeInExpo, easeOutExpo, easeInOutExpo – easeInCirc, easeOutCirc , easeInOutCirc */ const fast = 4269; const slow = 13000; const effect = easeInOutCuaic; const … Read more

Is there a way to have a Java8 duration of one year that accounts for leap years?

As per the response in Getting Duration using the new dateTime API you should be using Period p = Period.ofYears(1); It’s important to understand the difference between Duration (exact number of nanoseconds < 1 day) and Period (variable > 1 day). Duration won’t account for leap days, daylight savings time or leap seconds, for example, … Read more

get duration of audio file

MediaMetadataRetriever is a lightweight and efficient way to do this. MediaPlayer is too heavy and could arise performance issue in high performance environment like scrolling, paging, listing, etc. Furthermore, Error (100,0) could happen on MediaPlayer since it’s a heavy and sometimes restart needs to be done again and again. Uri uri = Uri.parse(pathStr); MediaMetadataRetriever mmr … Read more

html5 display audio currentTime

Here’s an example: <audio id=”track” src=”http://upload.wikimedia.org/wikipedia/commons/a/a9/Tromboon-sample.ogg” ontimeupdate=”document.getElementById(‘tracktime’).innerHTML = Math.floor(this.currentTime) + “https://stackoverflow.com/” + Math.floor(this.duration);”> <p>Your browser does not support the audio element</p> </audio> <span id=”tracktime”>0 / 0</span> <button onclick=”document.getElementById(‘track’).play();”>Play</button> This should work in Firefox and Chrome, for other browsers you’ll probably need to add alternative encodings.

MySQL storing duration time – datatype?

Storing it as an integer number of seconds will be the best way to go. The UPDATE will be clean and simple – i.e. duration = duration + $increment As Tristram noted, there are limitations to using the TIME field – e.g. “TIME values may range from ‘-838:59:59’ to ‘838:59:59’“ The days/hours/minutes/seconds display formatting won’t … Read more

Groovy time durations

If you just want to find the difference between two times you create yourself (for instance to see how long something takes to execute) you could use: import groovy.time.* def timeStart = new Date() // Some code you want to time def timeStop = new Date() TimeDuration duration = TimeCategory.minus(timeStop, timeStart) println duration If you … Read more