Start New Discussion within our Software Development Community

As many people new to python i seem to have run into a bit of a snag with an alarm program i was making. I wanted to make something that would play a song (.wav) at a given time and would not stop unless you played a little game, guess the number from 1 to 100.

Now my program works when i run it in pythonwin through the interactive window, however when i try to run it though cmd the music doesn't play. here's what i came up with;

from win32com.client import Dispatch
#set up music player
mp = Dispatch("WMPlayer.OCX")
tune = mp.newMedia("Therock.wav")
mp.currentPlaylist.appendItem(tune)

import time
import random
#alarm clock
print "Awesome Alarm Clock!"
print "Awesome Alarm will go off at 8:00AM"
not_exec = 1
while(not_exec):
    dt = list(time.localtime())
    hour = dt[3]
    minute = dt[4]
    if hour == 8 and minute == 00:
        not_exec = 0

mp.controls.play()

#turn off game
print "Guess the number to stop the music"
print "**********************************"
guess = input("Guess > ")
x = 0
rando = random.randint(1, 100)
while x == 0:

    if guess > rando:
        print
        guess = input("Nope too high try again ")
        mp.currentPlaylist.appendItem(tune)
    elif guess < rando:
        print
        guess = input("Nope too low try again ")
        mp.currentPlaylist.appendItem(tune)
    else:
        print "Congrats, now try to stay awake"
        x=1
        mp.controls.stop()

any help would be great.

That is usually a directory problem, i.e. it can't find something because it is not in the current directory. For this line, give it the absolute path name
tune = mp.newMedia("/complete/path/Therock.wav")
If that doesn't work, check that something is printed so you know the program was started. Finally, if you haven't found anything, use a try/except to catch error messages and see if anything is printed.

This article has been dead for over six months. Start a new discussion instead.