DVD Studio Pro, Jukebox scripts, random playback

Thanks to Alex Blanc today – he worked through a lot of binary based maths with me to help answer a fairly challenging question… how to set up a user selected playlist so that it plays back in a random order.

The issue is actually very complex. Last year we developed a user selected playlist allowing the viewer to choose up to nine clips from a total of 24 on offer. If you consider that each viewer will make their own choice this is in itself a random playback engine. However, what if the viewer wants to select the first nine clips and then play those back randomly without repeating any clips? This is the challenge!

It turns out to be possible, but all of the available memory slots in DVDSP are used at some point in the scripting. We adapted the Jukebox scripts as our starting point and used the same basic script structure – i.e. a selection script, a playback control script, a pre- playback script to clear some of the registers, a script to clear all registers and a script with all of the ‘jump’ statements in it.

Alex’s mastery of the coding environment meant that no script was over long, and he also introduced me to the ‘XOR’ function… if you have never used any binary maths functions then this is a tricky one to explain. It basically looks at two given memory slots and compares the entries in them. If both are the same it evaluates to ‘true’ otherwise it gives a ‘false’ response. Quite why we used XOR is more obvious when you look at the scripts themselves.

They are not fully finished yet – some fine tuning to do and so on, but you can get to them by going here:


and looking for the item called Jukebox_randomiser.sit. You will also see the original jukebox files there, too.

The basic mechanics of the scripting is that the user chooses a clip to play. The value of the button they select is then lodged into a five bit long section within a 16 bit register (there are eight of these at our disposal). The script then adds one to a counter and sends you back to the menu for the next choice if the counter is less than 9. Once the ninth choice has been made the script sends you to a menu to play the choices back. To do this it first generates a random number between 0 and 9 and uses this to look within one of three memory slots where the choices are stored. It then masks off the two sets of five bits that it isn’t using and works with the five bits it needs. These are then blanked to be zeros so that when it next looks it knows whether or not the choice has been played. By repeating this process the script tracks what has been played. If the random number generator picks the same number a second time the script subtracts one from it to attempt to find a new number not yet chosen…

I told you it was complex!

In time I will tidy this set of scripts up and sort out the remaining ‘end jumps’ for the tracks that use the scripts, then build a disc image for folks to download and try out. Currently there is also a section within two of the scripts which should be tidied up as it is very long winded (we couldn’t think of the shorter way to do it…sigh), but otherwise it all works as it should. I will eventually add comments to the scripts as well so as to keep track of what is going on should anyone else want to use them.

4 thoughts on “DVD Studio Pro, Jukebox scripts, random playback

  • 11 February, 2009 at 11:08 am

    I’ve just found your blog here, ’cause I’ve been looking for a solution to a DVD SP programming challenge. Having seen that you are a very experienced Pro regarding Jukebox scripts, my programming challenge might be “peanuts” for you 😉 Nevertheless I would be very pleased if you could confirm, that what I’ve planned to do is possible in DVD SP:

    I have a series of 90 short clips (exercises) in three groups (clip 1-30, 31-60, 61-90). I would like the user to have the possibility to chose a group as well as a number of exercises which will then be chosen randomly out of the selected group. In addition, the user should also have a possibility to chose 3, 5 or 7 repetitions of each exercise. Of course, each exercise should only appear once… Challenge or peanuts? 😉 And, is this possible with on-board technique in DVD SP?

    I would be very pleased to receive a feed-back from you,

    All the best


  • 12 February, 2009 at 12:12 am

    It’s possible, but not at all easy, and certainly a challenge!

    it can be done from within DVDSP, and you’ll need to do quite a lot of scripting. I see several things:

    1) you have to track the user choice as to the number of random clips to play from a set, and track which clips have actually played to avoid any repeats. This will take three/four GPRMs alone.

    2) You have to track how many iterations of each clip they want to play back (and is this each clip playing the specified number before moving on, or something different?). This will take another GPRM.

    3) You have to retain which group was originally chosen to work from – another GPRM or at least part of one.

    4) You have several tricky scripts to create – by no means a simple task to keep this all together.

    How much scripting have you done previously? Are you confident in what you need to do here? I’m pretty sure it is achievable, but it will be a time consuming job to get it right, to say the least!

  • 12 February, 2009 at 8:20 am

    Hello Hal

    thank you very much for your quick reply! I can see now, that this task is somehow too complex for the project since we are as well dealing with 4 different languages…! I guess it would be easier to define a set of various stories and select them randomly. Doing it this way, we would also not exceed the maximum GPRMs.

    Once again, thank you very much for your feed-back – I appreciate it very much

    All the best


  • 12 February, 2009 at 10:47 pm

    No problem – good luck with it!

Comments are closed.