$wsound

By hixxy on Nov 27, 2005

This snippet will let you retrieve info from media files on your computer.

The usage is the same as $sound ($sound().) but with different properties.

The properties you can use are:


album, albumartist, author, duration, filesize, filetype, genre, iscopyright, isvbr, publisher, title, track, trackingid, userlastplayedtime, userplaycount, userplaycountmorning, userplaycountafternoon, userplaycountevening, userplaycountnight, userplaycountweekday, userplaycountweekend, userrating or year.


If you specify the duration property then $wsound() will accept a second parameter to let you specify the $asctime() format the time should be returned in (eg: nn:ss for minutes:seconds).


This identifier relies heavily on windows media player (tested with the latest version (10.00.00.3646) but might work on earlier versions).


Some of the properties will only interest you if windows media player is the player you use to play your music, these are:


trackingid, userlastplayedtime, userplaycount, userplaycountmorning, userplaycountafternoon, userplaycountevening, userplaycountnight, userplaycountweekday, userplaycountweekend and userrating.


The trackingid is an ID number media player gives to each file.

The userlastplayedtime is the last time the file was played.

The userplaycount is the amount of times the file has been played all of the way through (if you play a song half way through and then stop it this number will not increment).

The userplaycountmorning is the amount of times the file has been played in the morning.

The userplaycountafternoon is the amount of times the file has been played in the afternoon.

The userplaycountevening is the amount of times the file has been played in the evening.

The userplaycountnight is the amount of times the file has been played in the night.

The userplaycountweekday is the amount of times the file has been played on a weekday.

The userplaycountweekend is the amount of times the file has been played on a weekend.

The userrating is the rating the file has been given.

alias wsound {
  if (!$istok(album albumartist author duration filesize filetype genre iscopyright isvbr publisher title track trackingid userlastplayedtime userplaycount $&
    userplaycountafternoon userplaycountevening userplaycountmorning userplaycountnight userplaycountweekday userplaycountweekend $&
    userrating year,$prop,32)) return E_INVALID_PROPERTY
  if (!$isfile($1)) return E_NO_SUCH_FILE
  .comopen wmp::temp WMPlayer.OCX
  if (!$com(wmp::temp)) return E_UNABLE_TO_OPEN_OBJECT
  !.echo -q $com(wmp::temp,Controls,3,dispatch* wmp::temp::controls)
  if (!$com(wmp::temp::controls)) {
    .comclose wmp::temp
    return E_UNABLE_TO_OPEN_OBJECT
  }
  !.echo -q $com(wmp::temp,Url,4,bstr,$1-)
  !.echo -q $com(wmp::temp::controls,Stop,3)
  !.echo -q $com(wmp::temp,currentMedia,3,dispatch* wmp::temp::currentmedia)
  if (!$com(wmp::temp::currentmedia)) {
    .comclose wmp::temp
    .comclose wmp::temp::controls
    return E_UNABLE_TO_OPEN_OBJECT
  }
  var %result = $(,,$com(wmp::temp::currentmedia,getItemInfo,3,bstr,$replace($prop,album,wm/albumtitle,albumartist,wm/albumartist,isprotected,is_protected, $&
    publisher,wm/publisher,track,wm/tracknumber,year,wm/year))) $com(wmp::temp::currentmedia).result
  .comclose wmp::temp
  .comclose wmp::temp::controls
  .comclose wmp::temp::currentmedia
  if ($prop == duration) && ($2) return $asctime(%result,$2)
  return %result
}

Comments

Sign in to comment.
Yoinx   -  Mar 08, 2006

then yeah, that would be why you dont have the object. Personally I never uninstall anything that comes with windows. for the simple fact that it removes their com objects. which more and more programs seem to milk lately.

 Respond  
Gex   -  Mar 08, 2006

there is lots of ways to uninstall mediaplayer...the simplest...visit the control panel add/remove programs then windows components. someppl dnt like windows mediaplayer (i am one of them) and install a basic mediaplayer like winamp or real or even jetaudio (my fav) ...

 Respond  
Yoinx   -  Mar 08, 2006

Gex, the com object is included in windows media player. So unless they uninstalled windows media player completely (im not even sure its possible) its a fair bet, they have it.

 Respond  
Gex   -  Mar 08, 2006

maybe cz some of them doesnt have the COM OBJECT \"WMPlayer.OCX\" ???

 Respond  
hixxy   -  Dec 04, 2005

I assume that means the snippet works for you? Good :)
Some people have reported that the snippet still doesn\'t work for them, yet it works for me and several others.

The problem with using COM is that something that works on one system could outright fail on the next. As you can imagine this can be annoying sometimes!

 Respond  
KuTsuM   -  Dec 03, 2005

Great job, hixxy :) I only wish I were this good at comobj\'s ;/

 Respond  
hixxy   -  Dec 01, 2005

The snippet wasn\'t working because you had to play the file to gather info from it, so I\'ve updated the snippet so that it plays and then instantly stops the file. Hopefully, even on fairly slow pcs, you shouldn\'t be able to hear the song before it stops playing, but someone tell me if you can hear it please.

 Respond  
Mpdreamz   -  Nov 30, 2005

I really think snippets are rated too low on here, awesome work hixxy. Knowing your work this works. when i get home ill test this out in a while loop on my mp3 dir, cant wait :p.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.