View Issue Details

IDProjectCategoryView StatusLast Update
0006689MMW v4Framework: Scripts/Extensionspublic2012-03-07 08:13
Reporterzvezdan Assigned To 
PrioritynoneSeverityfeatureReproducibilityN/A
Status assignedResolutionopen 
Product Version4.0 
Target Version4.1 
Summary0006689: OnBeforePlay event needed
DescriptionI need an event which could be handled after the current track finished with reproduction (OnPlaybackEnd) and before MM starts to play the next one (OnPlay).
Additional InformationDuring the requested event I need a possibility to decide which track should be played next, not matter which one is really on the list (which is unknown anyway when the Shuffle is turned on). This means that the next track from the internal "shuffle list" should not be removed from that list, but it should be remembered for playing after the forced one.

Some of my scripts have a possibility to intercept OnPlay event and to force MM to play some track instead of the intended one from NP. For example, Queue List has a possibility to play tracks from its list in the middle of reproduction of tracks from NP. It is not big problem if Shuffle is turned off, just put these tracks after the current one and they will play correctly, but when Shuffle is turned on then the scripts don't know in advance what is the next track (however, even if they could know such thing, it cannot help). So, my script wait at OnPlay event and when MM try to play the next track from its "shuffle list" my script force the program to play another track instead.

The current problem is because there is an interruption in playback of few seconds during that process, not manifested on my computers, but reported here: http://www.mediamonkey.com/forum/viewtopic.php?p=275674#p275674
TagsNo tags attached.
Fixed in build

Relationships

related to 0005924 resolvedLudek MMW 5 Framework: CUEPoint Support 

Activities

zvezdan

2010-11-18 19:49

updater   ~0021383

I just found some old request for same event by Steegy, really good explained: http://www.mediamonkey.com/forum/viewtopic.php?p=88685#p88685

peke

2011-01-23 01:32

developer   ~0022539

Wouldn't be enough that you use OnPlaybackEnd and Set CurrentSong to ID?

Or better to set which track would be next?

zvezdan

2011-01-23 08:31

updater   ~0022543

No, it cannot be used, I already tried that. The program stops the current playing song on the exit of the OnPlaybackEnd event handler, not matter if some new track is set to current using Set CurrentSong.

We cannot set which track would be next if Shuffle is turned on.

peke

2011-02-25 23:15

developer   ~0023423

So basically this means that in case that OnPlaybackEnd CurrentSong is set MM should follow that song as next even Shuffle is ON?

Will that handle that?

zvezdan

2011-02-26 01:04

updater   ~0023425

Well, I am not sure that your solution could handle even my example. You see, I need to know what song is going to play next, but in the OnPlaybackEnd event handler I could know only the current song which is finishing with the reproduction.

Here is some example how my Queue List script works. Let say that I have 5 tracks in the NP and let say that their random order of reproduction is 2, 5, 3, 4 and 1. Let say that program played the 2-nd tracks and it is in the middle of the reproduction of the 5-th track. Now, let say that I have added the 6-th track in NP and I want to play that track next. If I set CurrentSong = 6 in the OnPlaybackEnd event handler, would the program play all remaining tracks from the list after finish of that 6-th one (3, 4, 1)?

Here is another example, let say that I have tracks with same order of the reproduction (2, 5, 3, 4 and 1), and let say again that I have played 2-nd track and I am in the middle of the playback of the 5-th tracks and I want to force the program to play 4-th track as the next instead of the 3-rd as it was planed. So if use CurrentSong = 4 in the OnPlaybackEnd event handler, would the program play all remaining tracks from the list except that 4-th one (3, 1)?

Here is one more example with the explanation why I need to know what song is going to play next. Let say again that we have the same tracks as in previous examples and let say that in the middle of the reproduction of the 5-th track I want to force the program to play the 3-rd track. I don't know in advance that that track is actually the next one in the internal shuffling list. So, if I use CurrentSong = 3 in the OnPlaybackEnd event handler, wouldn't the program play that track twice in row?

I think there are also many other needs for the requested event which cannot be handled with your solution. For example, we recently had one request for such event in the Add-ons developer forum: "How to stop playback before any sound" (http://www.mediamonkey.com/forum/viewtopic.php?f=19&t=55784). There, the scripter want to turn off the volume depending of which track is the next, not to force the reproduction of some another track.

I suppose that your suggestion could even lead to some incompatibility with some existing scripts and because of that I would rather add the suggested event. That event could have one input/output integer argument - as input argument it would represent the index of the next track from NP planed for reproduction, but with a possibility for scripters to change that value to be able to force reproduction of some another track from NP.

rusty

2011-05-06 20:28

administrator   ~0024912

Please triage.

zvezdan

2012-03-02 15:15

updater   ~0030602

I just got one mail from one user reporting that there is one more problem with the current implementation of the Queue List script which cannot be avoided. Here is the excerpt: "would like to say that it works almost as on winamp, and that's awsome.

The only comment I have is regarding the "cross fade" effect. It does not seem to account for cross fade when it goes form a currently played track to playing a queued track. Is this something that is easy to fix in the script?"

You see, the problem is because the program is already playing the begin of the next track from its queue before I have a chance to tell MM to play the next track from my queue list in the OnPlay event handler. So, when I set CurrentSong to my track in the OnPlay event handler, the program would play a few seconds of that next track from its queue in fade out.

peke

2012-03-03 01:53

developer   ~0030605

Last edited: 2012-03-03 01:55

You are right, when crossfading is enabled MM do not handle events correctly.

From My experience there should be several new events/properties involved to handle Crossfading correctly.
Events:
OnCrossfadeStart
OnCrossfadeEnd

These would be useful so that you can insert Next track from your queue directly in crossfade.

Also to have much better overview when crossfade is happening it would be useful to have Player get Property Crossfade that will Return Number of Milliseconds till next OnCrossfadeStart will fire, positive number if crossfade is in effect and Empty in all other cases like Crossfade is disabled.

I also better described framework that can be used in handling crossfading much precise within 0005924

zvezdan

2012-03-03 17:18

updater   ~0030607

Last edited: 2012-03-03 17:23

Don't get me wrong, but I cannot see how your suggestion could solve my problem. First of all, I need a possibility to insert the next track from my queue not only when crossfade is turned on, but also when it is turned off.

I don't know how you are doing it internally, but after some listening I have an impression that your suggested OnCrossfadeStart event actually occurs in the same time as the current OnPlay. That also means that I cannot use your OnCrossfadeStart to intercept playing of the next track from your queue and insert my own track to play first because of the same reason why OnPlay event is not the best place for that, as I already explained.

Also, I think that your suggested OnCrossfadeEnd should be actually the same as OnPlaybackEnd, but that also means that OnPlay of the second track should be fired before OnPlaybackEnd of the first track in case when crossfade is turned on. Here is the simple timeline example of my suggestion where 1 is the playback of the first track only, x is the crossfade and 2 is the second track only:
...
1
1
1
1 - OnTrackEnd
12 - OnPlay
12
12
12 - OnPlaybackEnd
2
2
2
...

However, I am not sure if such order of events is recommended because of the compatibility. Anyway, I don't understand why someone would want to have some event handler when crossfade ends.

As you already know, currently we have this:
...
1
1
1
1 - OnTrackEnd, OnPlaybackEnd (CurrentSong = 1)
12 - OnPlay (CurrentSong = 2)
12
12
12
2
2
2
...

I just want this:
...
1
1
1
1 - OnTrackEnd, OnPlaybackEnd (CurrentSong = 1), OnBeforePlay (CurrentSong = 2, but if I change that value to x, then 2 should be played later)
1x - OnPlay (CurrentSong = x)
1x
1x
1x
x
x
x
...
x
x
x - OnTrackEnd, OnPlaybackEnd (CurrentSong = x), , OnBeforePlay (CurrentSong = 2)
x2 - OnPlay (CurrentSong = 2)
x2
x2
2
2
2
...

jiri

2012-03-06 10:58

administrator   ~0030624

Zvezdan, I don't understand - if you use OnTrackEnd event to set up your next playing track, is there any problem? Why a new event (OnBeforePlay) would be needed? Maybe I just don't understand how your script currently works...

zvezdan

2012-03-06 12:43

updater   ~0030626

I am sorry, I completely forgot that I have a conditional execution of my script depending of the MM version. When it is started within MM pre-1223 then I am using OnPlay event handler to force playback of my track, but if it is started with some newer version then I am using OnPlaybackEnd (since the b1223 was the first build with that event).

However, even with OnPlaybackEnd, I need to start one timer object with 1 millisecond delay and in its event handler I am forcing the playback of my track. If I force playback of my track in the OnPlaybackEnd directly, my track would not play at all. Here is the order of events if I force playback of my track in OnPlaybackEnd:
- OnPlay, CurrentSong = 1
- OnSeek, CurrentSong = 1
...
- OnTrackEnd, CurrentSong = 1
- OnPlaybackEnd, CurrentSong = 1, in that event handler I set CurrentSong = 5
- OnPlaybackEnd, CurrentSong = 1
- OnTrackProperties, CurrentSong = 1 (incremented Playcount)
- OnPlay, CurrentSong = 6 (if shuffle is turned off)
- OnPlay, CurrentSong = 6
...
- OnPlaybackEnd, CurrentSong = 6
- OnStop, CurrentSong = 6

Please note that there are two OnPlaybackEnd events one after another with the same (old) CurrentSong, also two OnPlay events one after another with the CurrentSong of the next track from the list after the forced track, i.e. the forced (wanted) track wasn't played at all.

But, if I force playback of my track in the timer's event handler I get this:
- OnPlay, CurrentSong = 1
- OnSeek, CurrentSong = 1
...
- OnTrackEnd, CurrentSong = 1
- OnPlaybackEnd, CurrentSong = 1, in that event handler I start timer with CurrentSong = 5
- OnPlay, CurrentSong = 2 (if shuffle is turned off)
- OnPlaybackEnd, CurrentSong = 2
- OnPlay, CurrentSong = 5 (as I want)
...
- OnPlaybackEnd, CurrentSong = 5
- OnStop, CurrentSong = 5

Unfortunately, even with that my trick when using the timer object I am getting the short interruption in playback when a begin of the unwanted song could be heard for a moment (in the previous example that would be the 2-nd song). It is not a problem if the 2-nd song has a silence on its begin, but if it starts at 96dB then it could be really irritating. Not to mention that I don't get the crossfade between 1-st and 5-th tracks if that option is turned on.

By the way, OnTrackEnd is nothing better for my problem than OnPlaybackEnd. Here is the order of events with it:
- OnPlay, CurrentSong = 1
- OnSeek, CurrentSong = 1
...
- OnTrackEnd, CurrentSong = 1, forcing to CurrentSong = 5
- OnPlaybackEnd, CurrentSong = 5
- OnPlay, CurrentSong = 6
...
- OnPlaybackEnd, CurrentSong = 6
- OnStop, CurrentSong = 6

If I use the timer object started in OnTrackEnd, I would get this:
- OnPlay, CurrentSong = 1
- OnSeek, CurrentSong = 1
...
- OnTrackEnd, CurrentSong = 1, started timer with CurrentSong = 5
- OnPlaybackEnd, CurrentSong = 1
- OnPlay, CurrentSong = 2
- OnPlaybackEnd, CurrentSong = 2
- OnPlay, CurrentSong = 5 (as I want)
...
- OnPlaybackEnd, CurrentSong = 5
- OnStop, CurrentSong = 5

You see, there is the same situation as with OnPlaybackEnd, i.e. I am getting the unwanted short part of the 2-nd song, and there is also the same problem with the crossfade. I cannot remember now, but I had some additional problem when using OnTrackEnd, so I decided to use OnPlaybackEnd.

zvezdan

2012-03-07 08:13

updater   ~0030637

Steps to reproduce the problem:
- start program;
- install Queue List add-on (http://solair.eunet.rs/~zvezdand/QueueList.htm);
- install Event Logger add-on (http://solair.eunet.rs/~zvezdand/EventLogger.htm);
- open Options dialog box, go to Event Logger sheet and turn on the next events: Play, TrackEnd and PlaybackEnd;
- turn on View | Event Viewer;
- clear Now Playing panel and place 3 tracks in it but without playing, just drag and drop them to NP, let 1-st and 3-rd be some moderate tracks and let 2-nd be some track which have a very loud begin from the start;
- turn off Shuffle;
- turn on Crossfade;
- open MediaMonkey DirectSound output configuration dialog box and turn off Fade in new track;
- select 1-st track from NP;
- click Play button (Ctrl+P);
- select 3-rd track from NP;
- choose Play | Queue Selected or press F3;
- move seek slider to 15 seconds before track end;
- listen very carefully for the track transition and observe Event Viewer panel -> you would hear for a moment a very loud begin of the 2-nd track when the 1-st track finish and immediately after that the 3-rd track would continue the playback, also there wouldn't be a fade out of the 1-st track.