From: Adam Shelly Date: 2006-01-17T03:48:41+09:00 Subject: Re: Newbie question on music/windows ------=_Part_6994_722166.1137437308599 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline I did almost all my testing in irb - where that set of lines worked perfectly, but when I tried to write a simple jukebox I ran into the same problem you did. There is some timing issue - the player is running in a separate thread or process, and it doesn't respond instantly to the ole calls. The quick solution I came up with was to add some sleeps between the calls. There's probably a better solution involving checking statuses. w =3D SimpleWinMediaPlayer.new w.volume =3D volume songlist.each {|song| puts (fullname =3D 'file://'+dirname+'/'+song) w.file=3D fullname sleep 0.1 w.play sleep 0.1 puts w.duration sleep (w.duration) while w.current_pos !=3D "" sleep (0.5) end } -Adam On 1/16/06, Jb Piacentino wrote: > > Adam Shelly wrote: > > This sounded like an interesting challenge - here's a simple interface > > to the Windows Media Player: > Wow !!! this is much more that I was expected ! Thanks millions for the > clear OLE usage example. > > > basic usage: > > player =3D SimpleWinMediaPlayer.new > > player.file =3D "c:/whatever.mp3" > > player.play > In my case, adding this snippet directly to my code does not seem to > kick anything like a WMP... It seems that player is correctly > initialized (I can do 'ole_methods 'and 'name'). '@control.playItem > @control.currentItem' is executed but does seem to succesfully launch a > play. Any idea ? > > Also, is there anything special about program termination ? Will the OLE > object survive ruby instance termination ? What should I write as a > waiting loop ? Any thread management needed ? > > Thanks again, > > Jb > > -- > Posted via http://www.ruby-forum.com/. > > ------=_Part_6994_722166.1137437308599--