Eos Question

All about the past, current and future webteases and the art of webteasing in general.
---
Post Reply
Roblsforbobls
Explorer At Heart
Explorer At Heart
Posts: 272
Joined: Tue May 21, 2019 2:27 am
Gender: Male
Sexual Orientation: Asexual
I am a: Switch

Eos Question

Post by Roblsforbobls »

Hi Eos/coding Milovanians! :-D

I am working on a tease that involves interacting with music, and I've run into a bit of a roadblock. I would like to either stop or pause a sound file and store (in a variable etc.) the number of seconds of the track that have elapsed. The music is on an infinite loop until stopped, and the tease is constantly moving between pages. The point in the track that the audio is stopped at is different every time, and I cannot predict it ahead of time.

A bit of background:
I have two audio files with the same song, except one of them is slightly sped up (1.25x speed). I do this so that at a given point I can increase the speed of the song that is currently playing. I would like to be able to keep the song playing and change the speed without the song restarting from the beginning (as if I was changing the playback speed on a YouTube video). I think I can do this if I can somehow store where the song is in one track and do a bit of math to determine where to seek in the new track. At this point though, the best I can do is restart the song from the beginning with a faster or slower speed.

If anyone can think of a way to make this work, I would be very appreciative! :-P
Roblsforbobls
Explorer At Heart
Explorer At Heart
Posts: 272
Joined: Tue May 21, 2019 2:27 am
Gender: Male
Sexual Orientation: Asexual
I am a: Switch

Re: Eos Question

Post by Roblsforbobls »

Update:
I realized that what I really need is a working stopwatch in javascript. I've looked at System.nanoTime() but it doesn't work in this version of Java? And if it does I don't know enough about coding to get it in the right format for it to work properly.

By using very roundabout means (involving a 30 ms long audio file, lots of data collection, and a polynomial of best fit), I have made an inaccurate and inconsistent stopwatch. Would love to know if there is a faster/easier/more accurate way (because I'm certain there is)!
kerkersklave
Explorer At Heart
Explorer At Heart
Posts: 709
Joined: Sun Jul 06, 2014 2:11 pm
Gender: Male
Sexual Orientation: Open to new ideas!
I am a: Slave

Re: Eos Question

Post by kerkersklave »

JavaScript is a completely different programming language than Java.
The name was probably created for marketing reasons by Netscape, a company that ceased to exist years ago.

In Javascript you can get a timestamp in Milliseconds with Date.now()
System.nanoTime() is Java.

I did not check whether Date.now() works in EOS, but I would expect it to. The basic things are available.
If it does not, I'll look into it further.
undeniable_denial
Explorer At Heart
Explorer At Heart
Posts: 109
Joined: Sat Aug 24, 2019 11:42 am
Gender: Male
Location: Germany

Re: Eos Question

Post by undeniable_denial »

Date.now() works. I have used it for something similar. Just store the current time in a variable when you start playback. Then when it stops, the difference is the playback time. Then you can seek to what should be (1/1.25)*playbacktime, if I'm not mistaken.

Code: Select all

start = Date.now();
Sound.get("slowMusic").play();

...

playbackTime = Date.now()-start;
Sound.get("slowMusic").pause();
Sound.get("fastMusic").seek(playbackTime/1.25/1000);
Sound.get("fastMusic").play();
The seek() function takes a number in seconds, while Date.now() returns milliseconds.

How gapless that is depends on the browser. It should be pretty good in Chrome. There might be a bit of a delay in Firefox.
Roblsforbobls
Explorer At Heart
Explorer At Heart
Posts: 272
Joined: Tue May 21, 2019 2:27 am
Gender: Male
Sexual Orientation: Asexual
I am a: Switch

Re: Eos Question

Post by Roblsforbobls »

undeniable_denial wrote: Sun Mar 08, 2020 12:08 pm Date.now() works. I have used it for something similar. Just store the current time in a variable when you start playback. Then when it stops, the difference is the playback time. Then you can seek to what should be (1/1.25)*playbacktime, if I'm not mistaken.

Code: Select all

start = Date.now();
Sound.get("slowMusic").play();

...

playbackTime = Date.now()-start;
Sound.get("slowMusic").pause();
Sound.get("fastMusic").seek(playbackTime/1.25/1000);
Sound.get("fastMusic").play();
The seek() function takes a number in seconds, while Date.now() returns milliseconds.

How gapless that is depends on the browser. It should be pretty good in Chrome. There might be a bit of a delay in Firefox.
Thank you both, I have it figured out now!
It turns out that the problem was I used a Say action to verify that the timer was working, and that the Say action was right after the eval I used to pause the music. Apparently the time between the Eval and the Say actions was too short for the event listener to update the variables in time for the Say action to show that the process worked. In fact, everything was working as intended already, only after my verification Say action was executed :lol: I placed a delay timer of 0.001 seconds between the eval and the Say action and that gave the event listener enough time to update the variables.
Post Reply