It is currently March 28th, 2024, 9:41 am

Track Time Remaining?

General topics related to Rainmeter.
Vetsus
Posts: 27
Joined: March 7th, 2017, 5:29 pm

Re: Track Time Remaining?

Post by Vetsus »

balala wrote:I wrote that code with the NowPlaying plugin. NowPlaying just partially supports Spotify, but on the forum you can find a plugin for Spotify: https://forum.rainmeter.net/viewtopic.php?p=94631#p94631
According to the manual, the NowPlaying plugin doesn't support the duration and position with Spotify, just the Artist and the Title, so probably my code doesn't work with Spotify. I don't use Spotify, so I can't even try it. Probably someone will help you here to adapt this to work with the SpotifyPlugin.
Sorry...
yeah, i do know that is says in the docs that it doesn't support that. but there are players which have found the runaround to that. so my player does display those for spotify. i would assume it should be able to calculate it the same way... however if i use the progress portion it give me -1:-1 for the values. if i change that and you use position portion of the measure i then get 00:00. neither of which are obviously correct.
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5380
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA
Contact:

Re: Track Time Remaining?

Post by eclectic-tech »

Vetsus wrote:yeah, i do know that is says in the docs that it doesn't support that. but there are players which have found the runaround to that. so my player does display those for spotify. i would assume it should be able to calculate it the same way... however if i use the progress portion it give me -1:-1 for the values. if i change that and you use position portion of the measure i then get 00:00. neither of which are obviously correct.
The Spotify plugin returns the duration and progress in different formats from what the NowPlaying plugin returns...
Spotify Plugin wrote:Length
Length of the track currently playing in seconds

Position
Current song position

Progress
Returns current track progress(between 0 and 1)
Not sure what value is returned for Position... but different calculations would be needed to get the results for time remaining.

In order to help, you need to post your skin code. (I also do not use Spotify, but someone may be able to find a solution after seeing your code.)
Vetsus
Posts: 27
Joined: March 7th, 2017, 5:29 pm

Re: Track Time Remaining?

Post by Vetsus »

i'm sorry, i didn't see this until obviously awhile later so i'm hoping i can still get some help with this. the code i'm using seems like it should be fairly identical or similar in some way other than it's using the spotify plugin vs the nowplaying plugin. but here is the code for the track progress or track time, as well as the track length:

Code: Select all

[Measure_TrackTime]
Measure=Plugin
Plugin=SpotifyPlugin.dll
PlayerName=Spotify
Type=Position
Substitute="00:00":"N\A"

[Measure_TrackLength]
Measure=Plugin
Plugin=SpotifyPlugin.dll
PlayerName=Spotify
Type=Length
Substitute="00:00":"N\A"
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Track Time Remaining?

Post by balala »

Vetsus wrote:but here is the code for the track progress or track time, as well as the track length:
Although I still don't use Spotify (as well as neither eclectic-tech doesn't), I will try however a reply. Don't take this as a fact, I'm not sure it'll entirely work, but if you won't get a better reply, maybe it worth a try...
According to the above posted code, it seems that the Spotify plugin returns the position and the length in the MM:SS format (I think this, due to the Substitute options, posted on both measures). First remove those two Substitute options (or at least comment them out, with some semicolons).
Then you'll need some measures, to convert the returned string format of the duration and progress, into seconds. Add the following measures to your code:

Code: Select all

[Measure_TrackTimeMinutes]
Measure=String
String=[Measure_TrackTime]
DynamicVariables=1
RegExpSubstitute=1
Substitute="^(\d+):(\d+)$":"\1"

[Measure_TrackTimeSeconds]
Measure=String
String=[Measure_TrackTime]
DynamicVariables=1
RegExpSubstitute=1
Substitute="^(\d+):(\d+)$":"\2"

[Measure_TrackLengthMinutes]
Measure=String
String=[Measure_TrackLength]
DynamicVariables=1
RegExpSubstitute=1
Substitute="^(\d+):(\d+)$":"\1"

[Measure_TrackLengthSeconds]
Measure=String
String=[Measure_TrackLength]
DynamicVariables=1
RegExpSubstitute=1
Substitute="^(\d+):(\d+)$":"\2"
The [Measure_TrackTimeMinutes] and [Measure_TrackTimeSeconds] measures will return the number of minutes, respectively seconds of the current position (changing while the playback is in progress), while the [Measure_TrackLengthMinutes] and [Measure_TrackLengthSeconds] measures will return the number of minutes and seconds of the duration.
Now with two Calc measures, you can calculate the number seconds of both (the position and the length):

Code: Select all

[Measure_TrackTime_InSeconds]
Measure=Calc
Formula=( 60 * [Measure_TrackTimeMinutes] + [Measure_TrackTimeSeconds] )
DynamicVariables=1

[Measure_TrackLength_InSeconds]
Measure=Calc
Formula=( 60 * [Measure_TrackLengthMinutes] + [Measure_TrackLengthSeconds] )
DynamicVariables=1
After all this is done, I think calculating the remaining time as a difference, is not too hard:

Code: Select all

[MeasureRemaining_InSeconds]
Measure=Calc
Formula=( Measure_TrackLength_InSeconds - Measure_TrackTime_InSeconds )
This last measure, will return the remaining time in seconds. You can easily convert the number, into a time format, using two Calc measures:

Code: Select all

[MeasureRemaining_Minutes]
Measure=Calc
Formula=( Floor ( MeasureRemaining_InSeconds / 60 ))
RegExpSubstitute=1
Substitute="^(\d{1})$":"0\1"

[MeasureRemaining_Seconds]
Measure=Calc
Formula=( MeasureRemaining_InSeconds - 60 * MeasureRemaining_Minutes )
RegExpSubstitute=1
Substitute="^(\d{1})$":"0\1"
Obviously the [MeasureRemaining_Minutes] measure will return the number of remained minutes and the [MeasureRemaining_Seconds] measure, the number of remained seconds.
Because I could try this code only with the NowPlaying plugin, I'm not very sure it'll work with the SpotifyPlugin. But try it, then please let me know if it does.
Vetsus wrote:i'm sorry, i didn't see this until obviously awhile later so i'm hoping i can still get some help with this.
About this, just mention that if you check the "Notify me when a reply is posted" checkbox below the field where you write your reply, you'll get an emaile, once someone replied to your message. Very easy and convenient, to not miss a reply...
Vetsus
Posts: 27
Joined: March 7th, 2017, 5:29 pm

Re: Track Time Remaining?

Post by Vetsus »

it certainly worked. however that's a lot of extra code just to get it to work....
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Track Time Remaining?

Post by balala »

Vetsus wrote:it certainly worked. however that's a lot of extra code just to get it to work....
Yeah, it is. But I suppose if you say it worked, you succeeded , right?
Post Reply