<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.mediamonkey.com/wiki/index.php?action=history&amp;feed=atom&amp;title=Python_event_handling</id>
	<title>Python event handling - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.mediamonkey.com/wiki/index.php?action=history&amp;feed=atom&amp;title=Python_event_handling"/>
	<link rel="alternate" type="text/html" href="https://www.mediamonkey.com/wiki/index.php?title=Python_event_handling&amp;action=history"/>
	<updated>2026-05-08T01:32:26Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.4</generator>
	<entry>
		<id>https://www.mediamonkey.com/wiki/index.php?title=Python_event_handling&amp;diff=6680&amp;oldid=prev</id>
		<title>Mcow: This example moved to Python event handling: bad original link</title>
		<link rel="alternate" type="text/html" href="https://www.mediamonkey.com/wiki/index.php?title=Python_event_handling&amp;diff=6680&amp;oldid=prev"/>
		<updated>2011-07-20T15:52:40Z</updated>

		<summary type="html">&lt;p&gt;&lt;a href=&quot;/wiki/This_example&quot; class=&quot;mw-redirect&quot; title=&quot;This example&quot;&gt;This example&lt;/a&gt; moved to &lt;a href=&quot;/wiki/Python_event_handling&quot; title=&quot;Python event handling&quot;&gt;Python event handling&lt;/a&gt;: bad original link&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 15:52, 20 July 2011&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Mcow</name></author>
	</entry>
	<entry>
		<id>https://www.mediamonkey.com/wiki/index.php?title=Python_event_handling&amp;diff=6678&amp;oldid=prev</id>
		<title>Mcow: New code sample</title>
		<link rel="alternate" type="text/html" href="https://www.mediamonkey.com/wiki/index.php?title=Python_event_handling&amp;diff=6678&amp;oldid=prev"/>
		<updated>2011-07-20T15:50:24Z</updated>

		<summary type="html">&lt;p&gt;New code sample&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;This is a Python script demonstrating the handling of MediaMonkey events from an external program.&lt;br /&gt;
&lt;br /&gt;
It requires Python and the pywin32 package.  This code was developed using Python 2.6; it should work for any Python 2.x (at least from 2.3 on), but may require changes for Python 3.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# monitor player events from MediaMonkey.  print event flag and player state info for each&lt;br /&gt;
# note: once started, script does not exit until MM is shut down.&lt;br /&gt;
import win32com.client&lt;br /&gt;
import pythoncom&lt;br /&gt;
import time&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
boolReps = [&amp;#039;F&amp;#039;, &amp;#039;T&amp;#039;]   # hacky!&lt;br /&gt;
quit = False&lt;br /&gt;
&lt;br /&gt;
class MMEventHandlers():&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        self._play_events = 0&lt;br /&gt;
&lt;br /&gt;
    def showMM(self):&lt;br /&gt;
        # note: MMEventHandlers instance includes all of SDBApplication members as well&lt;br /&gt;
        playing = self.Player.isPlaying&lt;br /&gt;
        paused = self.Player.isPaused&lt;br /&gt;
        isong = self.Player.CurrentSongIndex&lt;br /&gt;
        print &amp;#039;Play&amp;#039;, boolReps[playing], &amp;#039;; Pause&amp;#039;, boolReps[paused], &amp;#039;; iSong&amp;#039;, isong,&lt;br /&gt;
        if playing:&lt;br /&gt;
            print &amp;#039;&amp;gt;&amp;gt;&amp;#039;, self.Player.CurrentSong.Title[:40]&lt;br /&gt;
        else:&lt;br /&gt;
            print&lt;br /&gt;
&lt;br /&gt;
    def OnShutdown(self):   #OK&lt;br /&gt;
        global quit&lt;br /&gt;
        print &amp;#039;&amp;gt;&amp;gt;&amp;gt; SHUTDOWN &amp;gt;&amp;gt;&amp;gt; buh-bye&amp;#039; &lt;br /&gt;
        quit = True&lt;br /&gt;
    def OnPlay(self):       #OK&lt;br /&gt;
        self._play_events += 1&lt;br /&gt;
        print &amp;quot;PLAY #&amp;quot;,&lt;br /&gt;
        self.showMM()&lt;br /&gt;
    def OnPause(self):      #OK&lt;br /&gt;
        print &amp;quot;PAUS #&amp;quot;,&lt;br /&gt;
        self.showMM()&lt;br /&gt;
&lt;br /&gt;
    def OnStop(self):&lt;br /&gt;
        print &amp;quot;STOP #&amp;quot;,&lt;br /&gt;
        self.showMM()&lt;br /&gt;
    def OnTrackEnd(self):&lt;br /&gt;
        print &amp;quot;TRKE #&amp;quot;,&lt;br /&gt;
        self.showMM()&lt;br /&gt;
    def OnPlaybackEnd(self):&lt;br /&gt;
        print &amp;quot;PLYE #&amp;quot;,&lt;br /&gt;
        self.showMM()&lt;br /&gt;
    def OnCompletePlaybackEnd(self):&lt;br /&gt;
        print &amp;quot;LSTE #&amp;quot;,&lt;br /&gt;
        self.showMM()&lt;br /&gt;
    def OnSeek(self):       #OK&lt;br /&gt;
        print &amp;quot;SEEK #&amp;quot;,&lt;br /&gt;
        self.showMM()&lt;br /&gt;
    def OnNowPlayingModified(self):     #OK&lt;br /&gt;
        print &amp;quot;LIST #&amp;quot;,&lt;br /&gt;
        self.showMM()&lt;br /&gt;
&lt;br /&gt;
    # OnTrackSkipped gets an argument&lt;br /&gt;
    def OnTrackSkipped(self, track):  #OK (only when playing)&lt;br /&gt;
        print &amp;quot;SKIP #&amp;quot;,&lt;br /&gt;
        self.showMM()&lt;br /&gt;
        # the type of any argument to an event is PyIDispatch&lt;br /&gt;
        # here, use PyIDispatch.Invoke() to query the &amp;#039;Title&amp;#039; attribute for printing&lt;br /&gt;
        print &amp;#039;[&amp;#039;, track.Invoke(3,0,2,True), &amp;#039;]&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def monitor():&lt;br /&gt;
    # running the script will start MM if it&amp;#039;s not already running&lt;br /&gt;
    SDB = win32com.client.DispatchWithEvents(&amp;#039;SongsDB.SDBApplication&amp;#039;, MMEventHandlers)&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;** monitor started&amp;quot;&lt;br /&gt;
    while not quit:&lt;br /&gt;
        # required by this script because no other message loop running&lt;br /&gt;
        # if the app has its message loop (i.e., has a Windows UI), then&lt;br /&gt;
        # the events will arrive with no additional handling&lt;br /&gt;
        pythoncom.PumpWaitingMessages()&lt;br /&gt;
        time.sleep(0.2)&lt;br /&gt;
&lt;br /&gt;
    # note that SDB instance includes members of of the MMEventHandlers class&lt;br /&gt;
    print &amp;quot;** monitor stopped; received &amp;quot; + str(SDB._play_events) + &amp;quot; play events&amp;quot;&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;#039;__main__&amp;#039;:&lt;br /&gt;
        monitor()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mcow</name></author>
	</entry>
</feed>