Author Topic: MusicBee API  (Read 287289 times)

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34349
Its a lot of effort for me to maintain the C++ library and as no one appeared to be using it i have stopped adding to it.
But although the C++ library doesnt have the newer API calls it should still work, and has the basic functions that allow you to retrieve the current playing track, lyrics and picture, and control playback.
So if its missing particular API calls you need then let me know

slimmeke

  • Jr. Member
  • **
  • Posts: 51
Ok Tnx for you answer.

I have only one problem with tha API.
When I compile the C++ example of the Api I get an error.
I can't activate the plugin because of following error:
Dll entry point: Initialise was not found.
But there is an Initialise methode.
I hope somebody can help me with this problem.

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34349
can you be more specific about what error you get when compiling.
I am using Visual C++ - the example was done with v9, but i only have v10 now - it still compiles and runs fine for me.
As a guess for the missing entry point, the TestDll.def contains definitions for the entry points, and needs to be set as the "Module definition file" in the C++ linker/input settings (which is it when using the example project file)

e-motiv

  • Full Member
  • ***
  • Posts: 188
Steven,    I believe PluginNotifyType.RatingChanging is still not working properly (MB 2.0.4663).
 It seemed most of the time not working and very randomly working.  To help you discover what's wrong, I traced it a bit.
Here are the results of what a serie that I think could be reproducible.  Notice that only the first rating changing of the serie did it right! All the others tell the future rating:

For the record, in all the changing of ratings below, I always did it via key shortcut.

1 .restart MB,  playing song,  changng rating from "no rating" -> 1:
 RatingChanging - Rating: norating
 RatingChanged - Rating: 1
2. While still playing same song, 1->2:
 RatingChanging - Rating: 2
 RatingChanged - Rating: 2
3. Playing another song, switching back to above song, 2->1:
 RatingChanging - Rating: 1
 RatingChanged - Rating: 1
4. Playing a never played song (since MB started), no rating->1:
 RatingChanging - Rating: 1
 RatingChanged - Rating: 1

(I tried other ways with failed results, though different series)

Code
public void ReceiveNotification(string sourceFileUrl, NotificationType type)
{
string debug = "", rating ="";
// perform some action depending on the notification type
rating = mbAPI.Library_GetFileTag(sourceFileUrl, MetaDataType.Rating);
rating = rating=="0,0"?"0":rating==""?"norating":rating;
switch (type)
{
case NotificationType.PluginStartup:
// perform startup initialisation
myPlay(about.Name+" launched");
break;
case NotificationType.TagsChanging:
debug = " - Rating: " + rating;
myPlay("tagschanging");
break;
case NotificationType.RatingChanging:
debug = " - Rating: " + rating;
//myPlay("ratingchanging");
break;
case NotificationType.RatingChanged:
debug = " - Rating: " + rating;
myPlay("ratingchangedfrom");
myPlay("2"); //function not as the numbern but the word,  "to" :-)
myPlay(rating);
break;
case NotificationType.TagsChanged:
//debug = " - Rating: " + rating;
myPlay("changessaved");
break;
}
if (debug!="") Out(type + debug); //debug
}
  Developing @ e-motiv.net       --       Musicbee plugins: Speak Back - Ghost Tracks - Radio Dig

slimmeke

  • Jr. Member
  • **
  • Posts: 51
The C++ APi works tnx.
But I have a little question.
Is it possible to know the time of the current possition of the playing song?

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34349

e-motiv

  • Full Member
  • ***
  • Posts: 188
Steven,    I believe PluginNotifyType.RatingChanging is still not working properly (MB 2.0.4663).
Bump?
Or am I doing something wrong? (Details in my post above.)
  Developing @ e-motiv.net       --       Musicbee plugins: Speak Back - Ghost Tracks - Radio Dig

kogash

  • Guest
Steven, are query parameters ready yet?

 if they are can you show us an example? I'm not able to use the autoplaylists xml to filter anything!

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34349
are you looking to create your own custom query or is it the case that you are trying to retrieve auto-playlist files using Playlist_QueryFiles(filename).
If its the later then make sure the filename includes the full path ending with .xuatopf

if you are wanting to create your own custom queries then use this syntax - i know its not great and quite limited:
Library_QueryFiles("field=XXXX")
for multiple "and" conditions, separate each one by a null character '\0'
Library_QueryFiles("artist=XXXX" + '\0' + "album=YYYY")
there is no "or" syntax currently supported

another possibility for full flexibility would be for you to generate your own auto-playlist - they are just xml files, and then use the Playlist_QueryFiles(filename) API call to retrieve the files.
The key elements in the xml are:
  <Source Type="1">   this indicates the files are retrieved from the library
  <Conditions CombineMethod="All">    All or Any
  <Condition Field="FileDateAdded" Comparison="InTheLast" Value="6m" />
  </Conditions>

However the current API behavior is to only load cached playlist files that are in the Playlists folder of the musicbee library. I could easily change that so you could load your own generated .xautopf file on the fly
Last Edit: December 29, 2012, 07:35:23 PM by Steven

kogash

  • Guest
Library_QueryFiles("field=XXXX")
for multiple "and" conditions, separate each one by a null character '\0'
Library_QueryFiles("artist=XXXX" + '\0' + "album=YYYY")
there is no "or" syntax currently supported

That! But i need something like the quicksearch that is in the main window, it uses "all fields" as default, is there a metafield for "all fields"?
must i escape the query text anyway?

The Playlist_QueryFiles(filename) is not usefull because I must generate the xml on runtime so it will not be (and must not be) cached nor shown in the ui

Thanks a lot for your responses and your hard work!

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34349
generating the xml could be saved to a non-cached file so wouldnt update the UI or the API could take the xml string directly.
But in any case there is no syntax (xml or existing query parameter) to support searching all fields for text and i am not able to change anything at the moment anyway - it wouldnt be until after the new year

e-motiv

  • Full Member
  • ***
  • Posts: 188
Steven,    I believe PluginNotifyType.RatingChanging is still not working properly (MB 2.0.4663).
Bump?
Or am I doing something wrong? (Details in my post above.)
I really feel ignored   :'(
  Developing @ e-motiv.net       --       Musicbee plugins: Speak Back - Ghost Tracks - Radio Dig

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34349
the reason the rating is not the old value is because the notifications are asynchronous, so by the time you receive it, any call backs to retrieve the current rating will have in likelyhood already changed. Can you let me know what you are trying to achieve

slimmeke

  • Jr. Member
  • **
  • Posts: 51
What value will mbApiInterface.NowPlaying_GetArtwork() return? Is it a url to the artwork or a encrypted string with the artwork in it?

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34349
i didnt think anyone was using it, so i changed it to return a url as the picture can be very big for an encoded string.
If the API revision in the plugin interface file mbApiInterface.ApiRevision is <= 25 then its using the old way