[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Newbie question on music/windows

Jb Piacentino

1/12/2006 9:37:00 AM

Hi,

I am trying to build a simple application that needs to play mp3 files.

Has anyone ever done this with Ruby ? I guess I would need to do some
Windows Media player 'remote control', but, assuming this is an option,
I do not where to start. Any guidance, idea, link, whatsoever would be
extremely helpful.

Tia,

Jb

--
Posted via http://www.ruby-....


5 Answers

Wybo Dekker

1/12/2006 9:56:00 AM

0

Jb Piacentino

1/12/2006 10:25:00 AM

0

Wybo Dekker wrote:
>
> you may be interested in
> http://localhost:8808/doc_root/ruby-mp3info-0.4/rdoc/index.html

Yes I got this one, but this only deals with getting infos on the file -
does not help me with playing it !

--
Posted via http://www.ruby-....


Adam Shelly

1/12/2006 9:50:00 PM

0

This sounded like an interesting challenge - here's a simple interface
to the Windows Media Player:
---
# SimpleWinMediaPlayer.rb
# - Adam Shelly, January 2006
#
require "win32ole"
class SimpleWinMediaPlayer
def initialize
@mp = WIN32OLE.new("WMPlayer.ocx")
p @mp
@control = @mp.controls
end
def file= str
@mp.URL= str
@media = @mp.currentMedia
@control.currentItem = @media
end
def file
@mp.url
end
def play
if @control.isAvailable "play"
@control.play
else
@control.playItem @control.currentItem
end
end
def pause
@control.pause
end
def stop
@control.stop
end
def rewind
if @control.isAvailable "fastReverse"
@control.fastReverse
else
seek_to 0
end
end
def fforward
@control.fastForward
end
def current_pos
@control.currentPositionString
end
def seek_to pos
# takes argument as S[.ms] or "S[.ms]" or "[MM]:SS[:ms]"
if pos =~ /(\d*):(\d+)(:(\d*))?/
pos = $1.to_f*60+$2.to_f+$4.to_f/1000.0
end
@control.currentPosition = pos.to_f
end
def duration
@media.duration
end
end

----
basic usage:
player = SimpleWinMediaPlayer.new
player.file = "c:/whatever.mp3"
player.play

Hope this helps

-Adam

On 1/12/06, Jb Piacentino <jb@piacentino.com> wrote:
> Yes I got this one, but this only deals with getting infos on the file -
> does not help me with playing it !
>
> --


Jb Piacentino

1/16/2006 4:38:00 PM

0

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 = SimpleWinMediaPlayer.new
> player.file = "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-....


Adam Shelly

1/16/2006 6:49:00 PM

0

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 = SimpleWinMediaPlayer.new
w.volume = volume
songlist.each {|song|
puts (fullname = 'file://'+dirname+'/'+song)
w.file= fullname
sleep 0.1
w.play
sleep 0.1
puts w.duration
sleep (w.duration)
while w.current_pos != ""
sleep (0.5)
end
}


-Adam
On 1/16/06, Jb Piacentino <jb@piacentino.com> 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 = SimpleWinMediaPlayer.new
> > player.file = "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-....
>
>