|
|
Line 9: |
Line 9: |
| using SongsDB; | | using SongsDB; |
| </source> | | </source> |
|
| |
| ==Subscribing to events==
| |
| Subscribing to events does not work with external applications, like .NET applications if they make the connection to the MediaMonkey application. See:
| |
| * [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]
| |
| A solution is presented in:
| |
| * [http://www.mediamonkey.com/forum/viewtopic.php?f=2&t=14004&hilit=com+events MonkeyToys: VB.NET extension adding MCE remote support]
| |
|
| |
| ===Walkthrough===
| |
| This solution is based on making your assembly ComVisible, registering it and letting an auto-script in MediaMonkey create your application object. This can be accomplished by creating a class along the lines under.
| |
| * First build and run your program, then call the RegisterCOM() Method to register your application with COM.
| |
| ''(continued after C#-code)''
| |
|
| |
| <source lang="csharp">
| |
| using System.Reflection;
| |
| using System.Runtime.InteropServices;
| |
| using SongsDB;
| |
|
| |
| namespace SomeNamespace {
| |
| [ComVisible(true)] // this overrides [assembly: ComVisible(false)] (is set by project options dialog) so registry don't get bloated with unneeded types
| |
| public class EventTest {
| |
| public SDBApplication SDB { get; private set; }
| |
|
| |
| public static void RegisterCOM() {
| |
| RegistrationServices rs = new RegistrationServices();
| |
| rs.RegisterAssembly(Assembly.GetExecutingAssembly(),
| |
| AssemblyRegistrationFlags.SetCodeBase);
| |
| }
| |
| public static void UnRegisterCOM() {
| |
| RegistrationServices rs = new RegistrationServices();
| |
| rs.UnregisterAssembly(Assembly.GetExecutingAssembly());
| |
| }
| |
| public void Init(SDBApplication mm) {
| |
| this.SDB = mm;
| |
| this.SDB.set_Objects(Assembly.GetExecutingAssembly().GetName().Name, this);
| |
| this.SDB.OnPlay += () => { System.Windows.MessageBox.Show("OnPlay event fired!"); };
| |
| }
| |
| }
| |
| }
| |
| </source>
| |
| * Add an autoscript-to mediamonkey (ie. a file in ...\MediaMonkey\Scripts\Auto) named SomeScript.vbs that starts your application and runs the Init function. It's contents should be like this:
| |
| <source lang="vb">
| |
| Sub OnStartup
| |
| Set o = CreateObject("SomeNamespace.EventTest")
| |
| o.Init(SDB)
| |
| End Sub
| |
| </source>
| |
| * When you now start MediaMonkey it will connect to your application and event firing will work.
| |
| <!--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== | | ==Links== |