# Play a Music File

**URL:** <https://www.ruby-forum.com/t/play-a-music-file/119556>\
**Category:** Ruby\
**Created:** [November 7, 2007, 10:37pm UTC](https://www.ruby-forum.com/t/play-a-music-file/119556 "2007-11-07T22:37:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![superfly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/48db29/32.png) [@superfly](https://www.ruby-forum.com/u/superfly)\
**Post date:** [November 7, 2007, 10:37pm UTC](https://www.ruby-forum.com/t/play-a-music-file/119556/1 "2007-11-07T22:37:35Z")

</div>

😃 Hello,

I was wondering if there was a code that would play a file of music,  
when called upon?

Thanks.

---

<div class="post-metadata">

**Author:** ![superfly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/48db29/32.png) [@superfly](https://www.ruby-forum.com/u/superfly)\
**Post date:** [November 8, 2007, 12:48am UTC](https://www.ruby-forum.com/t/play-a-music-file/119556/2 "2007-11-08T00:48:52Z")

</div>

Tj Superfly wrote:

> 😃 Hello,
> 
> I was wondering if there was a code that would play a file of music,  
> when called upon?
> 
> Thanks.

require ‘win32ole’  
player = WIN32OLE.new(‘WMPlayer.OCX’)  
player.OpenPlayer(‘c:\music\van halen\right now.wma’)

> **[Automating Windows Media Player with Ruby](http://rubyonwindows.blogspot.com/2007/07/automating-windows-media-player-with.html)**
>
> My recent article about automating iTunes has resulted in several requests for a similar article about Windows Media Player (WMP). And so, w...

~Jeremy

---

<div class="post-metadata">

**Author:** ![superfly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/48db29/32.png) [@superfly](https://www.ruby-forum.com/u/superfly)\
**Post date:** [November 8, 2007, 1:26am UTC](https://www.ruby-forum.com/t/play-a-music-file/119556/3 "2007-11-08T01:26:49Z")

</div>

Quoth Tj Superfly:

> 😃 Hello,
> 
> I was wondering if there was a code that would play a file of music,  
> when called upon?
> 
> Thanks.

Or if you’re not on windows:

`mplayer my_music_file.wav`

Regards,

---

<div class="post-metadata">

**Author:** ![superfly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/48db29/32.png) [@superfly](https://www.ruby-forum.com/u/superfly)\
**Post date:** [December 14, 2007, 11:49pm UTC](https://www.ruby-forum.com/t/play-a-music-file/119556/4 "2007-12-14T23:49:45Z")

</div>

Hi,

thank you for the link, but it’s not what I was looking for. I do not  
need to play the mp3 file. I need to be able to analyze it on the  
backend; that is, to get its length in seconds, and possibly truncate it  
(not necessary). I was doing it in Java so far. If I can’t do this on  
the backend, I can’t switch to Ruby, which is what I would love to do.

Thanks.

Peter

Konrad M. wrote:

> Quoth Tj Superfly:
> 
> > 😃 Hello,
> > 
> > I was wondering if there was a code that would play a file of music,  
> > when called upon?
> > 
> > Thanks.
> 
> Or if you’re not on windows:
> 
> `mplayer my_music_file.wav`
> 
> Regards,

---

<div class="post-metadata">

**Author:** ![superfly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/48db29/32.png) [@superfly](https://www.ruby-forum.com/u/superfly)\
**Post date:** [December 14, 2007, 11:51pm UTC](https://www.ruby-forum.com/t/play-a-music-file/119556/5 "2007-12-14T23:51:17Z")

</div>

I responded to a wrong thread…

Peter

Petr Kout wrote:

> Hi,
> 
> thank you for the link, but it’s not what I was looking for. I do not  
> need to play the mp3 file. I need to be able to analyze it on the  
> backend; that is, to get its length in seconds, and possibly truncate it  
> (not necessary). I was doing it in Java so far. If I can’t do this on  
> the backend, I can’t switch to Ruby, which is what I would love to do.
> 
> Thanks.
> 
> Peter
> 
> Konrad M. wrote:
> 
> > Quoth Tj Superfly:
> > 
> > > 😃 Hello,
> > > 
> > > I was wondering if there was a code that would play a file of music,  
> > > when called upon?
> > > 
> > > Thanks.
> > 
> > Or if you’re not on windows:
> > 
> > `mplayer my_music_file.wav`
> > 
> > Regards,
