Adding a reference to MediaMonkey: Difference between revisions

From MediaMonkey Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
Here you can find resources related to automating MediaMonkey in .NET (C#/VB.NET), including very simple beginners tips & tricks.
==Adding a reference to MediaMonkey==
# Choose Add Reference
# Choose Add Reference
# Go to the COM Tab
# Go to the COM Tab
Line 10: Line 7:
</source>
</source>


==Subscribing to events==
[[Category:.NET]]
* According to Forum Posts subscribing to events does not work with external applications, like .NET applications:
** [https://www.mediamonkey.com/forum/viewtopic.php?f=19&t=29201&p=291459 Events don't work with C#]
** [https://www.mediamonkey.com/forum/viewtopic.php?f=19&t=45676&p=297214 Trouble With Handling COM Events]
* There is however some talk about a solution in:
** [http://www.mediamonkey.com/forum/viewtopic.php?f=2&t=14004&hilit=com+events MonkeyToys: VB.NET extension adding MCE remote support]
 
Check out the post by stax76 on Tue Dec 26, 2006 11:08 am.  Possibly this code could work:
<source lang="csharp">
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Reflection;
using SongsDB;
 
namespace WindowsApplication1 {
  [ComVisible(true)]
  // this overrides [assembly: ComVisible(false)]
  // (is set by project options dialog)
  // so registry don't get bloated with unneeded types
  public class Program {
    public SDBApplication SDB;
    Timer tmr = new Timer();
 
    [STAThread]
    public static void Main() {
      if (MessageBox.Show("Click yes to install, no to uninstall",
          Application.ProductName, MessageBoxButtons.YesNo) == DialogResult.Yes) {
        RegistrationServices rs = new RegistrationServices();
        rs.RegisterAssembly(
          Assembly.GetExecutingAssembly(),
          AssemblyRegistrationFlags.SetCodeBase
          );
      }
      else {
        RegistrationServices rs = new RegistrationServices();
        rs.UnregisterAssembly(Assembly.GetExecutingAssembly());
      }
    }
 
    public void Init(SDBApplication mm) {
      string AssemblyName = Assembly.GetExecutingAssembly().GetName().Name;
      SDB = mm;
      SDB.set_Objects(AssemblyName, this);
      // Line under WORKS, lets the MM player start playing
      ((Program)SDB.get_Objects(AssemblyName)).SDB.Player.Play();
 
 
      SDB.OnPlay += new ISDBApplicationEvents_OnPlayEventHandler(SDB_OnPlay);
 
      tmr.Interval = 3000;
      tmr.Enabled = true;
      tmr.Tick += new EventHandler(tmr_Tick);
      tmr.Start();
    }
 
    void tmr_Tick(object sender, EventArgs e) { // THIS IS EXECUTED!
      tmr.Enabled = false;
      SDB.Player.Volume = 0.2;
      MessageBox.Show("timer");
    }
 
    void SDB_OnPlay() { // THIS IS EXECUTED!
      SDB.Player.Volume = 0.5;
      MessageBox.Show("onplay");
    }
  }
}
</source>
 
==Links==
* [[Scripting|Scripting main page]]
* [[MediaMonkey Automation objects]]
* [[MediaMonkey Database structure]]
* [[Introduction to scripting#About external scripts and applications|About external scripts and applications]]

Latest revision as of 18:03, 29 May 2011

  1. Choose Add Reference
  2. Go to the COM Tab
  3. Choose "MediaMonkey Library"

The base Namespace for MediaMonkey is SongsDB:

  using SongsDB;