Author Topic: MusicBee API  (Read 285438 times)

Cyano

  • Guest
So I'm experimenting and creating a new plugin, It needs the latest API Revision for "NowPlayingList_GetFileTags" method.

However with the latest API Revision,

The MB_AddMenuItem Delegate has been changed to: 

        public delegate System.Windows.Forms.ToolStripItem MB_AddMenuItemDelegate(string menuPath, string hotkeyDescription, EventHandler openHandler, EventHandler closeHandler);

So now it takes four parameters instead of three in the previous API, yet I can't seem to get it to work correctly.
Here is the code:


I can't see any problem with the method call, yet when I start MusicBee (Latest forum post version 2.5.5469),
I get this error:

Now I'm not sure If this is an error on my part or a bug with the API, so I was wondering if anyone can tell me the problem. The adding menu item seems to work correctly with a lower version of the API.

---
And one last question,

        public delegate bool Library_GetFileTagsDelegate(string sourceFileUrl, MetaDataType[] fields, ref string[] results);

What exactly is the sourceFileUrl parameter asking for? I can understand that the second parameter wants the array of data/tag types I want and the results are passed by reference in the third parameter. If I want to query the MusicBee Library - what exactly do I need to pass to sourceFileUrl.

Thanks,
Cyano

boroda

  • Sr. Member
  • ****
  • Posts: 4595
        public delegate bool Library_GetFileTagsDelegate(string sourceFileUrl, MetaDataType[] fields, ref string[] results);

What exactly is the sourceFileUrl parameter asking for? I can understand that the second parameter wants the array of data/tag types I want and the results are passed by reference in the third parameter. If I want to query the MusicBee Library - what exactly do I need to pass to sourceFileUrl.
sourceFileUrl is a file path, e.g C:\music\track1.mp3

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34312
it looks like i messed up the following definitions - just change them manually and i will later update the official API file:
Code
        public delegate System.Windows.Forms.ToolStripItem MB_AddMenuItemDelegate(string menuPath, string hotkeyDescription, EventHandler handler);
        public delegate bool MB_AddTreeNodeDelegate(string treePath, string name, System.Drawing.Bitmap icon, EventHandler openHandler, EventHandler closeHandler);

the intention is i never break or change existing API calls
Last Edit: December 23, 2014, 07:39:27 AM by Steven

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34312
the following API methods are available for the 2.5 series - the interface files and template are available in the first page

- retrieves information about the artwork associated with a music file
 bool Library_GetArtworkEx(string sourceFileUrl, int index, bool retrievePictureData, ref PictureLocations pictureLocations, ref string pictureUrl, ref byte[] imageData);

- updates the artwork associated with a music file
bool Library_SetArtworkEx(string sourceFileUrl, int index, byte[] imageData);

- gets information about the available visualisers and the current state
bool MB_GetVisualiserInformationDelegate(out string[] visualiserNames, out string defaultVisualiserName, out WindowState defaultState, out WindowState currentState);

- activates (or de-activates) a visualiser
bool MB_ShowVisualiserDelegate(string visualiserName, WindowState state);

- gets information about the available views for a plugin (currently only the theater mode plugin "mb_TheaterModePlugin.dll") and the current state
bool MB_GetPluginViewInformationDelegate(string pluginFilename, out string[] viewNames, out string defaultViewName, out WindowState defaultState, out WindowState currentState);

- activates (or de-activates) a plugin view
bool MB_ShowPluginViewDelegate(string pluginFilename, string viewName, WindowState state);

- gets the currently available output devices including any UPnP devices
bool Player_GetOutputDevicesDelegate(out string[] deviceNames, out string activeDeviceName);

- sets the active output device
bool Player_SetOutputDeviceDelegate(string deviceName);
Last Edit: January 13, 2015, 08:14:36 PM by Steven

htsign

  • Guest
Hi, I have 3 questions.

First, how to write the path of context menu of lyrics display area?
I understood that
  • "context.Main" is main playlist
  • "context.NowPlaying" is nowplaying playlist
But I don't know lyrics area's one.

Next, is there a method to add lyrics to current song?
I wrote the code below instead of to relate lyrics and songs.
Code
private void SaveLyrics(string lyrics)
{
    string filePath = mbApiInterface.NowPlaying_GetFileUrl();
    string dirPath  = Path.GetDirectoryName(filePath);
    string fileName = Path.GetFileNameWithoutExtension(filePath) + ".lrc";

    string targetPath = Path.Combine(dirPath, fileName);
    try
    {
        using (var stream = new StreamWriter(targetPath, false))
        {
            stream.Write(lyrics);
            stream.Flush();
        }
        mbApiInterface.Library_SetFileTag(mbApiInterface.NowPlaying_GetFileUrl(), Plugin.MetaDataType.HasLyrics, "Y [synched]");
    }
    catch (IOException)
    {
        MessageBox.Show("Failed to write", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}
I also doubt "NowPlaying_GetFileUrl" method with "MetaDataType.HasLyrics" is effective.
Anyway, I want to use it if there is a method to add lyrics.

Last, I hesitated this question is proper for this thread,
It seems the MusicBee Lyrics time line tag's parser takes "[01:23.45]" as not "[1:23.450]" but "[1:23.045]".
Some websites (e.g. Wikipedia) wrote the format is "[mm:ss.xx]".
I think it is original format. Let me know if it is wrong.

Thanks.

leo_r

  • Guest
Hello!

I'm trying to create a playlist. The following code used to work (probably on 2.3.something) but now doesn't (using 2.5.5524)

Code
_mbApiInterface.Playlist_CreatePlaylist(playlistDir, playlist.Name, mbPlaylistSongFiles);

where playlistDir is a string to the playlist directory, playlist.Name is a string containing the name of the playlist I want to create and mbPlaylistSongFiles is a string array of paths to the songs I want to add.

Is this something that's changed in 2.5? I notice that the playlist file format changed, possibly in 2.3? Did this only work before then? I'm not actually sure what version it last worked with.

If this isn't the way to do it, how would I:

- Create a new playlist and add songs to it and
- Clear a playlist of songs and add re-add a new list to it

Thanks!

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34312
working fine here. Can you expand upon "it doesnt work"

leo_r

  • Guest
working fine here. Can you expand upon "it doesnt work"

Sorry - I really should have been more descriptive (or possibly not tried to ask questions so late at night).

Calling the function simply returns a null object. No exceptions are thrown, it's definitely being called (if I set a break point, it gets hit), but no playlist is created in MusicBee.

I'm not at home right now - I'll investigate further this evening. Would a malformed (or somehow not-acceptable-to-MusicBee) playlist path or name throw an exception, or just silently fail?

leo_r

  • Guest
Further to my last post,
the exact function call which fails looks something like this:

Code

playlistDir = "C:\\Users\\Leo\\Music\\MusicBee\\Playlists\\"
playlist.Name = "Music I Like 2"
mbPlaylistSongFiles = {string[11]}

Where the string array is an array of things that look something like this:
[9] = "D:\\Music\\Music-15\\Criolo - Convoque Seu Buda\\10-Fio De Prumo (Padê Onã).mp3"

_mbApiInterface.Playlist_CreatePlaylist(playlistDir, playlist.Name, mbPlaylistSongFiles);

Typing this, I thought perhaps the issue was because of the weird characters in the above song, so I tried it again with a new playlist using songs which only have ASCII characters in the name - no difference. Function is called (breakpoint hit) but no playlist appears at the path in playlistDir.

Any thoughts? Could it be my installation (somehow?)

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34312
use the logical name for the playlist folder
starting from the root folder = ""
so you would use "Classicial\1950s" for sub-folder "1950s" of folder "Classical"
Last Edit: February 18, 2015, 08:50:58 PM by Steven

leo_r

  • Guest
Crucial missing information! Thanks. I thought the code I had used to work (in 2013), although it's possible I was wrong...

Lepick

  • Guest

Hi Steven, I can't create a menu item under the 'Tools' menu as shown in the MB wiki tutorial.

Edited 4/30/15 - Never mind. I had started with an older API. Downloaded again today, works great.



Last Edit: April 30, 2015, 10:49:56 PM by Lepick

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34312
for MB v3, a change is being made to the API for creating embeded panels: MB_AddPanel where dock=PluginPanelDock.NowPlaying
in the current and earlier MB versions that API created a "UserControl" panel. In v3, the panel inherits from "Control" so that means if you depend on usercontrol properties such as scrollbar sizing/ positioning etc then it wont work.
I am not aware of anyone other than myself creating plugins using this API call but if you are and have concerns then let me know. There are a couple of approaches that can be taken.
The change is because the underlying controls MB uses/ supports has been substantially changed

zorexx

  • Jr. Member
  • **
  • Posts: 36
Steven, may I know when will you release the MusicBee API for v3?
I am thinking that since v3 is just around the corner, I will target v3 for the next version of my plugin MusicBeeIPC, but I can't do so until I have the API for v3.

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34312
V3 is focused on GUI changes and I dont anticipate making any API changes unless someone asks for something specific