I want to write a command that launches iTunes and play the first song that is in the playlist or random song ,for now I can only launch iTunes from my code but it doesn't start the song automatically, I added --play but its doesn't work ..it there away to make it work? my aiml pattern is here 

```<category> <pattern> PLAY MUSIC FROM MY COMPUTER </pattern> <template> <random> <li>Sure thing! </li> <li>OKAY, </li> <li>OK! </li> </random> <system> open -a /Applications/itunes.app/Contents/MacOS/itunes/play</system> </template> </category>```


3 years 8 months ago


You can do it this way in the AIML:

<category><pattern>PLAY MUSIC</pattern>
        <li>Sure thing!</li>
        <li>Playing music now</li>
<category><pattern>STOP MUSIC</pattern>
        <li>As you please</li>
        <li>Stopping music now</li>
<category><pattern>PAUSE MUSIC</pattern>
        <li>Music in pause</li>
        <li>Pausing music now</li>
<category><pattern>RESUME MUSIC</pattern>
        <li>Resuming music now</li>

And then you add a python script for each command. First one includes the path to your music directory:

import random

def play():
    global musiconoff
    musiconoff = 1
    musicpath = C:\Users\tommy\itunes\Media\
    files = os.listdir(musicpath)
    #i01.mouth.speakBlocking("playing song" + str(song))
    AudioPlayer.playFile(musicpath + str(song) , False)
    print("playing song:" + str(song))

# pause method
def pause():
    if musiconoff == 1:
      print "set music on pause"

# resume method
def resume():
    if musiconoff == 1:
      print "resuming music"
# stopped method is called when at the end of an audio file
def stop():
    if musiconoff == 1:
        print "stop playing"

The issue with this, is that it won't open or select music in subdirectories.

I don't have the time to dig further, but this gives you already a way to make it work it out.

I have just added this to the InMoov develop and it works nicely.