Author Topic: MusicBee API  (Read 285401 times)

thegreyspot

  • Guest
Ok fair enough.Java is just what i learnt in school and is what the Android OS uses :(

carloscs

  • Full Member
  • ***
  • Posts: 162
If you really, really, really  want to you can look into IKVM.

But I would just do it  with visual studio, much simpler, and c# has many similarities to java, so it should be easy to get into.


gavin19

  • Guest
Thanks for the API and the example (huge help). I only know a tiny bit of VB but I was able to make myself a plugin to save a list of played tracks to a log file. Not exactly earth shattering in it's scope, but it's of use to me. Cheers :)

kelsos

  • Sr. Member
  • ****
  • Posts: 302
I was checking about a configuration panel for a plugin I am working, and I found this "not implemented yet: height in pixels that musicbee should reserve in a panel for config settings. When set, a handle to an empty panel will be passed to the Configure function" is it still not implemented?

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34312
i forgot about that. I will do it this weekend

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34312
this is a new MusicBee.exe that supports the in-built panel for entering config settings. It will be in the next weekly update as well
http://www.mediafire.com/?a7ymkpdn944vtcs

One thing to be aware, the Configure command can be called more than once during a MB session. When (if) that happens, a handle to a new empty panel is passed so the panel needs to be populated from scratch

C#:
using System.Drawing;
using System.Windows.Forms;

public bool Configure(IntPtr panelHandle)
{
   // save any persistent settings in a sub-folder of this path
   string dataPath = mbApiInterface.Setting_GetPersistentStoragePath();
   // panelHandle will only be set if you set about.ConfigurationPanelHeight to a non-zero value
   // keep in mind the panel width is scaled according to the font the user has selected
   if (panelHandle != IntPtr.Zero) {
      Panel configPanel = (Panel)Panel.FromHandle(panelHandle);
      Label prompt = new Label();
      prompt.AutoSize = true;
      prompt.Location = new Point(0, 0);
      prompt.Text = "prompt:";
      TextBox textBox = new TextBox();
      textBox.Bounds = new Rectangle(60, 0, 100, textBox.Height);
      textBox.TextChanged += textBox_TextChanged;
      configPanel.Controls.AddRange(new Control[] {prompt,textBox   });
   }
   return true;
}

private void textBox_TextChanged(object sender, EventArgs e)
{
   // save the value
}

VB:
Imports System.Drawing
Imports System.Windows.Forms

    Public Function Configure(ByVal panelHandle As IntPtr) As Boolean
        ' panelHandle will only be set if you set about.ConfigurationPanelHeight to a non-zero value
        ' keep in mind the panel width is scaled according to the font the user has selected
        If panelHandle <> IntPtr.Zero Then
            Dim configPanel As Panel = Panel.FromHandle(panelHandle)
            Dim prompt As New Label
            prompt.AutoSize = True
            prompt.Location = New Point(0, 0)
            prompt.Text = "prompt:"
            Dim textBox As New TextBox
            textBox.Bounds = New Rectangle(60, 0, 100, textBox.Height)
            AddHandler textBox.TextChanged, AddressOf textBox_TextChanged
            configPanel.Controls.AddRange(New Control() {prompt, textBox})
        End If
        Return True
    End Function

    Private Sub textBox_TextChanged(ByVal sender As Object, ByVal e As EventArgs)
        ' save the value
    End Sub
Last Edit: March 21, 2011, 08:45:46 AM by Steven

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34312
from MB v1.2.4097+
Changes to the API - you need to get the latest MusicBeeInterface file from the example liinks below (however it should be backwards compatible so no need to rebuild an already released dll unless you are doing a lyrics or artwork plugin)

Lyrics and Artwork
for lyrics and artwork plugins, the following function needs to return an array of names of providers that your plugin supports

public string[] GetProviders()

the interface for RetrieveLyrics and RetrieveArtwork now includes a parameter for the provider you should return lyrics or artwork from - the idea being MB will iterate through the providers one by one in the order specified in MB Tags(2) preferences

public string RetrieveLyrics(string sourceFileUrl, string artist, string trackTitle, string album, bool synchronisedPreferred, string provider)
public string RetrieveArtwork(string sourceFileUrl, string albumArtist, string album, string provider)


Updating file tags
Library_SetFileTag(sourceFileUrl, type, value) now updates a "pending changes" cache rather than directly updating the internal MB library cache. This is so you cant end up with the cache being out-of-synch with tags in the files
Library_CommitTagsToFile(sourceFileUrl) updates the music file as before
MB_RefreshPanels() is a new function that should be called when you have finished updating the files (if updating many files its not a good idea to call as each file is updated as it will slow things down a lot)

new function returns the window handle for MB:
IntPtr handle = mbApiInterface.MB_GetWindowHandle();

updated examples
C++
http://www.mediafire.com/?mmt2p0vv5f26ty2
C#
http://www.mediafire.com/?ezf48kdce1yakci
VB
http://www.mediafire.com/?fr5msmdbxixtbrb
Last Edit: March 21, 2011, 11:19:02 PM by Steven

kelsos

  • Sr. Member
  • ****
  • Posts: 302
May I ask, the controls used in the application are custom? I am currently working on a Now Playing plugin for Skype, easy enough but I have some issues with the look an feel of the controls (button and checkbox specifically) in the settings panel. Any suggestions on what should I search/read in order to achieve a similar optical outcome, so that they 'll look like similar to the other controls?

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34312
there is an exposed function
Setting_GetSkinElementColour
that returns the colours used for the skin the user has selected (its quite limited though in what elements you can get the values for)
but anyway, as i have done some of the controls myself such as the radio box and buttons, it might be better if expose an api call so that MB creates a control and returns the handle to it so you can add to your panel. I might not be able to look at it for some time though

kelsos

  • Sr. Member
  • ****
  • Posts: 302
Yeah I already use that, but still some controls look like they are out of place. Though the idea of the future API call is nice, it could make it easier for the developers to make settings menu that looks like the rest of the application. Anyway at the moment I should probably look on how to make some custom controls that look at least similar to the rest. I am already working (or at least trying too) on a custom button. It would be a nice experience.

Maleko12

  • Member
  • Sr. Member
  • *****
  • Posts: 658
how is the skype plugin working out?

Elberet

  • Full Member
  • ***
  • Posts: 167
While you're looking at letting MB create custom-styled controls, would it be possible to add an API call to get the fonts and font sizes used throughout MB? (Especially for buttons...)

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34312
i wont be doing this for some time, but for the fonts just get that from the panel handle thats passed to the Configure function eg. Panel.FromHandle(panelHandle).Font
I'll just mention i will be updating the API for the next update to support Storage and Streaming handling (to handle Media Servers) and one of the changes will also be to allow exposing a SaveSettings function. So you wont need your button for that anymore.

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34312
added the following (see the updated examples file in the first post)
- new API for:
  SaveSettings()
  called by MusicBee when the user clicks "Apply" or "Save" in the preferences screen. Its up to your plugin to figure out if the settings have changed and need to be saved

- several API methods to support retrieval and stream of files on a server. Its probably best to contact me if you want to add support for a media server

Elberet

  • Full Member
  • ***
  • Posts: 167
However, there are different fonts for buttons and labels -- at least the font size on MusicBee's own buttons is noticeably smaller then the font size used for most labels.

Do you have any guidelines on how large a plugins' configuration panel may get? Would modal dialog windows be acceptable?