944,150 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 331
  • Python RSS
Nov 8th, 2009
0

Alarm Question

Expand Post »
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;

Python Syntax (Toggle Plain Text)
  1. from win32com.client import Dispatch
  2. #set up music player
  3. mp = Dispatch("WMPlayer.OCX")
  4. tune = mp.newMedia("Therock.wav")
  5. mp.currentPlaylist.appendItem(tune)
  6.  
  7. import time
  8. import random
  9. #alarm clock
  10. print "Awesome Alarm Clock!"
  11. print "Awesome Alarm will go off at 8:00AM"
  12. not_exec = 1
  13. while(not_exec):
  14. dt = list(time.localtime())
  15. hour = dt[3]
  16. minute = dt[4]
  17. if hour == 8 and minute == 00:
  18. not_exec = 0
  19.  
  20. mp.controls.play()
  21.  
  22. #turn off game
  23. print "Guess the number to stop the music"
  24. print "**********************************"
  25. guess = input("Guess > ")
  26. x = 0
  27. rando = random.randint(1, 100)
  28. while x == 0:
  29.  
  30. if guess > rando:
  31. print
  32. guess = input("Nope too high try again ")
  33. mp.currentPlaylist.appendItem(tune)
  34. elif guess < rando:
  35. print
  36. guess = input("Nope too low try again ")
  37. mp.currentPlaylist.appendItem(tune)
  38. else:
  39. print "Congrats, now try to stay awake"
  40. x=1
  41. mp.controls.stop()

any help would be great.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
herebutfortea is offline Offline
1 posts
since Nov 2009
Nov 8th, 2009
0
Re: Alarm Question
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.
Reputation Points: 741
Solved Threads: 694
Nearly a Posting Maven
woooee is offline Offline
2,314 posts
since Dec 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Rectangles in functions?
Next Thread in Python Forum Timeline: Pythagoras?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC