Author Topic: Retrieving the StreamHandle of the Playing Track  (Read 1444 times)

Mayibongwe

  • Sr. Member
  • ****
  • Posts: 1733
  • Heal The World
In the future, I will convert this plugin to a generalized hotkey provider, as and when the requests come up.
Bookmarking this in case the wishlist request goes cold: AB Repeat
Tonight, I wanted to get something going for this request.
Along the way, I discovered that the playStateChanged notification seems not to be kicking in at all.

________

Unrelated to this bug report:
I actually can't think of how I'll get the tracks to repeat between two points using the current API.

So far, I'm able to capture both the user's start and end times.
Able to get it to commence the loop at A.
My challenge now comes in figuring out how to determine that the track has reached point B.
Calling Player_GetPosition() non-stop to figure out how much longer till B would be crazy.

At this moment, I can only see this working if MB was to receive a value from the plugin telling it to stop at such a position.
For example, PlayerSetEndPosition()

Edit: Subject line amended from the initial false bug report.
Last Edit: August 31, 2024, 06:34:29 PM by Mayibongwe
Strength and Honour (2025)

boroda

  • Hero Member
  • *****
  • Posts: 5219
won't MB stop playback/skip to the next track automatically at the "end position"? all you need are working notifications for "play state changed" and "playing track changed" events (not sure if the notification for the latter event exists now).

Mayibongwe

  • Sr. Member
  • ****
  • Posts: 1733
  • Heal The World
PlayingTrackChanged already exists.

But the type of function I'm gunning for is to allow users to set an AB repeat point in real time by means of a hotkey.
Getting MusicBee to know what the "end position" has been temporarily set to is my struggle.

Edit:

won't MB stop playback/skip to the next track automatically at the "end position"?
It will indeed based on the endPosition defined in the duration of the file itself, or the endTime defined in the Tag Editor.
What I'd wish to have was a way to get MusicBee to respect a plugin's own endTime set for a particular track.
Last Edit: August 31, 2024, 07:38:26 AM by Mayibongwe
Strength and Honour (2025)

Mayibongwe

  • Sr. Member
  • ****
  • Posts: 1733
  • Heal The World
I just remembered that Steven has a track_previewer plugin that can play the first 30 seconds of any given song.
I wonder how it is determining that 30s has elapsed.
I've gone through the API and can't see anything obvious.
Strength and Honour (2025)

Steven

  • Administrator
  • Hero Member
  • *****
  • Posts: 34976
i sent you the previewer plugin code - its ancient so suggest you just get the parts of interest and use them for ideas. The key thing is to define the InitialiseStream(handle) function so MB will send the bass handle for the active stream and then use the bass library to get the position from a timer

Steven

  • Administrator
  • Hero Member
  • *****
  • Posts: 34976
can you be specific with what is not working with PlayStateChanged notification?

Mayibongwe

  • Sr. Member
  • ****
  • Posts: 1733
  • Heal The World
Sorry Steven, I just realized my stupidity.
My test environment was only set to receive tag events. I just updated this to player events and it's all good now [facepalm].

And thanks for the previewer plugin code. It's certainly a good pointer.
Will tinker around with this.
Strength and Honour (2025)

Mayibongwe

  • Sr. Member
  • ****
  • Posts: 1733
  • Heal The World
The key thing is to define the InitialiseStream(handle) function so MB will send the bass handle for the active stream and then use the bass library to get the position from a timer
Thanks a bunch Steven. The whole thing is practically up and running now.
Though I need your insight once more as it appears that InitialiseStream is not triggered on MusicBee startup.

i.e. on a fresh session showing the last played track in a paused state, InitialiseStream is not triggered upon resume.
So I don't have the handle for this track (tried to call Player_OpenStreamHandle for the NowPlayingUrl without success).

In short, I now have the AB Repeat going on for every subsequent song after the first.

Edit: There's a hack I could try to force the trigger, but I'll first wait in case you opt to amend things on your side.
Last Edit: August 31, 2024, 06:37:12 PM by Mayibongwe
Strength and Honour (2025)

Steven

  • Administrator
  • Hero Member
  • *****
  • Posts: 34976

Mayibongwe

  • Sr. Member
  • ****
  • Posts: 1733
  • Heal The World
Thanks Steven. I've upgraded to v3.6.9010 P, but I'm not able to see a difference on my install.
There's a file I'm logging the plugin progress to located in ...\appData\mb_RepeatAB\... and it's not registering any handle upon track resumption @ startup.

For now, I think we can leave it at this stage and review it when reports start to pour in the plugin thread about the function not working on the first track.
Even then, I will probably then incorporate the hack I planned which would involve initiating playback on plugin initialization and pausing it immediately without the user noticing.
Strength and Honour (2025)

Steven

  • Administrator
  • Hero Member
  • *****
  • Posts: 34976
MB wont open a stream on startup unless you have "resume position" or playback set in the Player preferences

Mayibongwe

  • Sr. Member
  • ****
  • Posts: 1733
  • Heal The World
Yesterday, i went into my preferences to check what I have there.
And "resume position" is what's set and has always been since I first configured MusicBee.
So reply #7 and 9 were tested under that condition and both times, the streamHandle just wasn't coming through for the first track after resuming playback.

Later this week, I will look into whether the stream gets created when "resume playback" is set instead.
But in any case, you don't have to spend more time on this for now. It can be reviewed at a later date.
The AB_Repeat plugin is functional enough as-is at this stage. Thanks for helping with getting it setup.
Strength and Honour (2025)