ISDBApplicationEvents problems with Remote Apps

This forum is for questions / discussions regarding development of addons / tweaks for MediaMonkey for Windows 4.

Moderators: Gurus, Addon Administrators

Gingernut63
Posts: 236
Joined: Thu Jul 14, 2011 4:13 am

ISDBApplicationEvents problems with Remote Apps

Post by Gingernut63 »

I have a problem with MonkeySqueeze that when remote control apps modify "Now Playing" no changes are noted in the script.

The script uses the "OnNowPlayingModified" event to monitor any changes to the Now Playing list. This works very well for any changes initiated via the MediaMonkey GUI but no modifications are noted when adding tracks via remote control apps, e.g. MonkeyTunes. I have replicated this on more than one app.

It appears that "OnNowPlayingModified" does not work with remote control apps, if that is the case are there any alternatives?

Edit: A bit more research finds that there are problem with Events from any "out-of-process" applications, so that explains the present problem. Suggestions on a work around are appreciated.
Last edited by Gingernut63 on Sat Nov 10, 2012 8:13 pm, edited 1 time in total.
MonkeySqueeze – Squeezing music into your life!
https://twitter.com/#!/MonkeySqueeze1
MonkeySqueeze Support: http://www.mediamonkey.com/forum/viewto ... =2&t=59515
MonkeySqueeze Development: http://www.mediamonkey.com/forum/viewto ... 19&t=59907
MediaMonkey user since 2005
Peke
Posts: 17486
Joined: Tue Jun 10, 2003 7:21 pm
Location: Earth
Contact:

Re: ISDBApplicationEvents problems

Post by Peke »

Hi, I was not being able to replicate using MM script to change/add/remove tracks from now playing. Events are triggered correctly. Can you make MM script that triggers issue?
Best regards,
Peke
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
Image
How to attach PICTURE/SCREENSHOTS to forum posts
Gingernut63
Posts: 236
Joined: Thu Jul 14, 2011 4:13 am

Re: ISDBApplicationEvents problems

Post by Gingernut63 »

Peke wrote:Hi, I was not being able to replicate using MM script to change/add/remove tracks from now playing. Events are triggered correctly. Can you make MM script that triggers issue?
Thanks for the reply Peke.

I've included the following code which is a section of the MonkeySqueeze script. the full script is found here: http://www.mediamonkey.com/forum/viewto ... 45#p333888

Code: Select all

'borrowed from a teknojunky - if you want the popups add them to this and then just call logme
Sub logme(msg)
  Dim fso, logf

  On Error Resume Next
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set logf = fso.OpenTextFile(Script.ScriptPath&".log",ForAppending,True)
  logf.WriteLine Now() & ": " & msg
  Set fso = Nothing
  Set logf = Nothing
End Sub
'*************************************************************
'Perl is taking the JSON strings directly into variables - "\" is a special character in perl to escape the following string
'wherever we have a "\" we need it to be "\\" in anything that goes to Perl (ie: anything that goes to SqueezeBox)
Function perlEscape(str1)
  perlEscape = Replace(str1, "\", "\\")
End Function
'*************************************************************
Sub registerEvents
  Call Script.RegisterEvent(SDB,"OnPlay","Event_OnPlay")
  Call Script.RegisterEvent(SDB,"OnPause","Event_OnPause")
  Call Script.RegisterEvent(SDB,"OnStop","Event_OnStop")
  Call Script.RegisterEvent(SDB,"OnSeek","Event_OnSeek")
  Call Script.RegisterEvent(SDB,"OnTrackEnd","Event_OnTrackEnd")
  Call Script.RegisterEvent(SDB,"OnShutdown","Event_OnShutdown")
  Call Script.RegisterEvent(SDB,"OnNowPlayingModified","Event_OnNowPlayingModified")
End Sub
'*************************************************************
Sub Event_OnNowPlayingModified
  Dim MMcount

  MMcount = SDB.Player.CurrentPlayList.Count
  logme("Now playing modified")
  logme("Aantal MM tracks: " & Cstr(MMcount))
  logme("Aantal LMS tracks: " & Cstr(LMScount))
  If SqueezeBoxMode = "stop" Then
    FillPlaylist
  ElseIf MMcount = 0 Then
    ResetPlaylist
  ElseIf MMcount < LMScount Then
    TracksDeleted(MMcount)
  ElseIf MMcount > LMScount Then
    TracksAdded(MMcount)
  Else
    TracksMoved
  End If
End Sub
Using the log function in the script while modifying the track list in Now Playing via the MM GUI returned the following values which indicate tracks being deleted. MonkeySqueeze then operated correctly and sent the required changes to the Squeezebox system.
11/11/2012 8:01:36 AM: Now playing modified
11/11/2012 8:01:36 AM: Aantal MM tracks: 5
11/11/2012 8:01:36 AM: Aantal LMS tracks: 6
11/11/2012 8:02:08 AM: Now playing modified
11/11/2012 8:02:08 AM: Aantal MM tracks: 4
11/11/2012 8:02:08 AM: Aantal LMS tracks: 5
Using the Monkeytunes/TunesRemote+ app to add tracks resulted in the tracks appearing in the MM Now Playing window but no activity was recorded in the log file and hence no interaction with MonkeySqueeze. The "OnNowPlayingModified" event did not note any activity. Play, stop, pause etc... work without a problem however.
MonkeySqueeze – Squeezing music into your life!
https://twitter.com/#!/MonkeySqueeze1
MonkeySqueeze Support: http://www.mediamonkey.com/forum/viewto ... =2&t=59515
MonkeySqueeze Development: http://www.mediamonkey.com/forum/viewto ... 19&t=59907
MediaMonkey user since 2005
Melloware
Posts: 339
Joined: Mon Aug 18, 2008 9:46 am
Location: Philadelphia, PA, US
Contact:

Re: ISDBApplicationEvents problems with Remote Apps

Post by Melloware »

To add info my MonekyTunes plugin is an C# COM object running in process with MM so I could receive all the events properly. So it's possible I am adding tracks to the Now Playing list incorrectly but here is my code that adds tracks to Now Playing from MonkeyTunes/TunesRemote+...

Code: Select all

string sql = BuildTracksSQL(tracksResponse);
if (!String.Empty.Equals(sql)) {
	if (clearQueue) {
		LOG.Info("Clearing current playlist cue");
		MediaMonkey.Player.PlaylistClear();
		ClearQueue = false;
	}
	SDBSongIterator iterator = QuerySongs(sql);
	while (!iterator.EOF) {
		SDBSongData track = iterator.Item;
		MediaMonkey.Player.PlaylistAddTrack(track);
		iterator.Next();
	}
}
I basically run a SQL query and get an SDBSongIterator back and loop through the results adding to the MM com object with MediaMonkey.Player.PlaylistAddTrack(track);

Does that help narrow the issue down?
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Melloware Inc.
MonkeyTunes - DACP Server for MediaMonkey
Intelliremote - Take Back Control of your HTPC!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Gingernut63
Posts: 236
Joined: Thu Jul 14, 2011 4:13 am

Re: ISDBApplicationEvents problems with Remote Apps

Post by Gingernut63 »

Melloware wrote:To add info my MonekyTunes plugin is an C# COM object running in process with MM so I could receive all the events properly. So it's possible I am adding tracks to the Now Playing list incorrectly but her

I basically run a SQL query and get an SDBSongIterator back and loop through the results adding to the MM com object with MediaMonkey.Player.PlaylistAddTrack(track);

Does that help narrow the issue down?
I have to admit my programming abilities are limited so it might be best If I could get you to run the following script which is based on subroutines in the MonkeySqueeze script. Very basic stuff as you can see.

The script that will display a warning popup whenever the Now Playing window is modified, or Play or Pause are initiated. It will also log the events provided you have full access to the Auto folder.

All popups appear when using the MM GUI. MonkeyTunes initiates the Play and Pause events, however the NowPlayingModified event does not occur when adding tracks. Other remote apps either do the same or occasionally initiate the NowPlayingModified event i.e. when moving tracks but not adding tracks. Would be very interested in your feedback.

Code: Select all

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' ISDBApplicationEvent Logging Script
' 
' Play 
' Pause
' NowPlayingModified
' 
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Option Explicit

Sub OnStartup
  Call Script.RegisterEvent(SDB,"OnPlay","Event_OnPlay")
  Call Script.RegisterEvent(SDB,"OnPause","Event_OnPause")
  Call Script.RegisterEvent(SDB,"OnNowPlayingModified","Event_OnNowPlayingModified")
End Sub

Sub logme(msg)
  Dim fso, logf

  On Error Resume Next
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set logf = fso.OpenTextFile(Script.ScriptPath&".log",ForAppending,True)
  logf.WriteLine Now() & ": " & msg
  Set fso = Nothing
  Set logf = Nothing
End Sub

Sub Event_OnPlay
  Dim Warning, Res
  
  logme("Play Initiated")
  Warning = Warning & vbNewLine & "Play Initiated"
  If Warning <> "" Then
    Res = SDB.MessageBox("ISDBApplicationEvent:" & vbNewLine & _
    Warning, mtWarning, Array(mbOk))
  End If
End Sub

Sub Event_OnPause
  Dim Warning, Res
  
  logme("Pause Initiated")
  Warning = Warning & vbNewLine & "Pause Initiated"
  If Warning <> "" Then
    Res = SDB.MessageBox("ISDBApplicationEvent:" & vbNewLine & _
    Warning, mtWarning, Array(mbOk))
  End If
End Sub

Sub Event_OnNowPlayingModified
  Dim Warning, Res
  
  logme("Now playing modified")
  Warning = Warning & vbNewLine & "Now Playing Modified"
  If Warning <> "" Then
    Res = SDB.MessageBox("ISDBApplicationEvent:" & vbNewLine & _
    Warning, mtWarning, Array(mbOk))
  End If
End Sub
MonkeySqueeze – Squeezing music into your life!
https://twitter.com/#!/MonkeySqueeze1
MonkeySqueeze Support: http://www.mediamonkey.com/forum/viewto ... =2&t=59515
MonkeySqueeze Development: http://www.mediamonkey.com/forum/viewto ... 19&t=59907
MediaMonkey user since 2005
Gingernut63
Posts: 236
Joined: Thu Jul 14, 2011 4:13 am

Re: ISDBApplicationEvents problems

Post by Gingernut63 »

Peke wrote:Hi, I was not being able to replicate using MM script to change/add/remove tracks from now playing. Events are triggered correctly. Can you make MM script that triggers issue?
I've created a little script based on the subroutines in MonkeySqueeze that will initiate a warning popup whenever a NowPlayingModified event is triggered. I have included it in the above post to Melloware: http://www.mediamonkey.com/forum/viewto ... 01#p351201

Does this work with the proposed MM app?
MonkeySqueeze – Squeezing music into your life!
https://twitter.com/#!/MonkeySqueeze1
MonkeySqueeze Support: http://www.mediamonkey.com/forum/viewto ... =2&t=59515
MonkeySqueeze Development: http://www.mediamonkey.com/forum/viewto ... 19&t=59907
MediaMonkey user since 2005
mmote
Posts: 22
Joined: Mon Mar 19, 2012 10:29 am

Re: ISDBApplicationEvents problems with Remote Apps

Post by mmote »

You're right, OnNowPlayingModified is only triggered in some cases. PlaylistInsertTracks causes the event to fire, whereas PlaylistAddTrack doesn't.
PlaylistClear, PlaylistDelete, PlaylistMoveTrack also do not trigger the event.
Gingernut63
Posts: 236
Joined: Thu Jul 14, 2011 4:13 am

Re: ISDBApplicationEvents problems with Remote Apps

Post by Gingernut63 »

mmote wrote:You're right, OnNowPlayingModified is only triggered in some cases. PlaylistInsertTracks causes the event to fire, whereas PlaylistAddTrack doesn't.
PlaylistClear, PlaylistDelete, PlaylistMoveTrack also do not trigger the event.
Thanks for the confirmation and info. Has now been added to Mantis after bug report.

See http://www.mediamonkey.com/forum/viewto ... =7&t=68520 for reference.

Cheers
MonkeySqueeze – Squeezing music into your life!
https://twitter.com/#!/MonkeySqueeze1
MonkeySqueeze Support: http://www.mediamonkey.com/forum/viewto ... =2&t=59515
MonkeySqueeze Development: http://www.mediamonkey.com/forum/viewto ... 19&t=59907
MediaMonkey user since 2005
Melloware
Posts: 339
Joined: Mon Aug 18, 2008 9:46 am
Location: Philadelphia, PA, US
Contact:

Re: ISDBApplicationEvents problems with Remote Apps

Post by Melloware »

I can confirm the same thing MMOTE reported with MonkeyTunes.

So hopefully the MM team will fix this issue and trigger that event.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Melloware Inc.
MonkeyTunes - DACP Server for MediaMonkey
Intelliremote - Take Back Control of your HTPC!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Gingernut63
Posts: 236
Joined: Thu Jul 14, 2011 4:13 am

Re: ISDBApplicationEvents problems with Remote Apps

Post by Gingernut63 »

Melloware wrote:I can confirm the same thing MMOTE reported with MonkeyTunes.

So hopefully the MM team will fix this issue and trigger that event.
Thanks for the confirmation.
MonkeySqueeze – Squeezing music into your life!
https://twitter.com/#!/MonkeySqueeze1
MonkeySqueeze Support: http://www.mediamonkey.com/forum/viewto ... =2&t=59515
MonkeySqueeze Development: http://www.mediamonkey.com/forum/viewto ... 19&t=59907
MediaMonkey user since 2005
Post Reply