CFire Posted April 11, 2007 Share Posted April 11, 2007 (edited) I have made this UDF with the help of lod3n because i wanted a way to change the volume of output from my program without affecting the rest of the comuter's volume settings. when i found this it gave a ton more than just volume control. Hope you find it useful. It TOTALLY replaces any use of Sound.au3 that is needed in ur scripts. It uses a Windows Media Player Com Object to run everything. I gave an Example script along with it, but these functions are rather simple to use. Edit: (4.12) Made The example script use a fileopendialog Edit: (4.14) Corrected a bug due to the indexing of the StringSplit() function. I just add a '+ 1' at the end of line 203. Thanks birdofprey Edit: (4.24) Changed the way the functions are called. You no longer need to call the Objcreate() function instead that is taken care of in a new function, WMStartPlayer(). The Object Variable is kept track of by WMMedia.au3. You still need to pass a Song Object when needed for certain Functions. When your script is Exiting, Run WMClosePlayer(). Only Opening and Closing the Player once seems to reduce the Constant increase in Memory used by the script. All the functions are the same minus the need to Pass the $pObj to it. Downloads : (4.24) - 124WMMedia.au3WMMedia_Example.au3 Edited April 24, 2007 by CFire [u]Scripts and UDF's[/u]WMMedia - UDF full of functions to Control Media Output. Link to comment Share on other sites More sharing options...
joeyb1275 Posted April 11, 2007 Share Posted April 11, 2007 Wow Man! Nice Job!! Link to comment Share on other sites More sharing options...
Gollum Posted April 11, 2007 Share Posted April 11, 2007 Just what I wanted, thanks for sharing. Link to comment Share on other sites More sharing options...
Xenobiologist Posted April 11, 2007 Share Posted April 11, 2007 Hi, nice seems to work! So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
lod3n Posted April 11, 2007 Share Posted April 11, 2007 Hey cool! I didn't even notice this. Great job. [font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font] Link to comment Share on other sites More sharing options...
birdofprey Posted April 14, 2007 Share Posted April 14, 2007 It seems I found a bug ! You need to modify line nr. 203 to $iState = $pObj.playState() + 1 in order to get it work properly. It's just a workaround though, anyhow, the problem comes from StringSplit, that assigns to $array[0] the number of elements, and because of this the whole array is pushed one position... took me half a day to figure out why my script was "reporting" the currently playing script as being "paused" It took me that long, because I was rewriting my script, and... it was a lot to be rewritten. One more thing. I get an error described here: Link in the "Transitioning" faze... After I click on the msgbox, the song starts playing though. Link to comment Share on other sites More sharing options...
CFire Posted April 15, 2007 Author Share Posted April 15, 2007 it sounds like its a problem with your default sound device. both the sound.au3 and wmmedia.au3 use what ever default sound device windows has registered. if you have a sound card and also have an onboard sound device on your motherboard then disable the one you are not using. the onboard one can be disabled in your computer's bios settings. other than that .... i don't know what could be going wrong. [u]Scripts and UDF's[/u]WMMedia - UDF full of functions to Control Media Output. Link to comment Share on other sites More sharing options...
Pascal257 Posted April 15, 2007 Share Posted April 15, 2007 Very good UDF! I'll use it for sure =)) Link to comment Share on other sites More sharing options...
birdofprey Posted April 19, 2007 Share Posted April 19, 2007 (edited) This windows media object seems to be a resource hog... seeks for example are much more "difficult" now than with the Sound UDF. On top of this the application I created is eating up more and more memory after each song it plays. More exactly, when it starts playing those files. It might be that I did something wrong, but, I presume that a WMCloseMedia is really needed here. Setting $pObj = 0 is not working. Trying to close the object this way after a song has been played and recreating it for each new song, made me end up with dozens of such objects. I now only create a... $pObj once and reuse the object but, the private bytes allocated for the application are still increasing on every "songload". Edited April 19, 2007 by birdofprey Link to comment Share on other sites More sharing options...
BillLuvsU Posted April 19, 2007 Share Posted April 19, 2007 very nice job man. I'm impressed. Opens all new doors for audio... now only if someone would come out with some amazing graphic UDFs. =] [center][/center]Working on the next big thing.Currently Playing: Halo 4, League of LegendsXBL GT: iRememberYhslaw Link to comment Share on other sites More sharing options...
CFire Posted April 22, 2007 Author Share Posted April 22, 2007 This windows media object seems to be a resource hog... seeks for example are much more "difficult" now than with the Sound UDF.On top of this the application I created is eating up more and more memory after each song it plays. More exactly, when it starts playing those files. It might be that I did something wrong, but, I presume that a WMCloseMedia is really needed here. Setting $pObj = 0 is not working. Trying to close the object this way after a song has been played and recreating it for each new song, made me end up with dozens of such objects. I now only create a... $pObj once and reuse the object but, the private bytes allocated for the application are still increasing on every "songload".I looked into this a bit further than i had before. I looked to see if there was a way to even close or delete the object but all i found was that the Object variable assigned by the ObjCreate() function is just a pointer to an object not the object itself. And i also found this in the Autoit help file about objectsObject variables behave a bit different than other types of AutoIt variables. An Object is not a real value, but a 'pointer' to something outside the script. So you can't perform arithmetic's, nor equations on Object variables. When you assign an Object variable a different value, the 'pointer' will automatically be released. You can, for instance, force deletion of an Object by assigning it any number or any text value.$oHTTP = ObjCreate("winhttp.winhttprequest.5.1") ; Object is created$oHTTP=0 ; Object is deleted You don't need to delete Objects when you are finished. If a script exits, AutoIt tries to release all active references to Objects that had been created in the script. Same thing happens when you had defined a local Object variable inside a function, and the function ends with a return.So my guess is that setting $pObj = 0 is the way to go. I also having seen this and trying to test it futher, tried running this on my own and I saw no recurring increase in memory usage from my system. I have no clue what could have caused this for you, but I'm pretty sure it wasn't my UDF. [u]Scripts and UDF's[/u]WMMedia - UDF full of functions to Control Media Output. Link to comment Share on other sites More sharing options...
pdaughe Posted April 22, 2007 Share Posted April 22, 2007 CFire, Thank you very much for sharing this. WOW -- great contribution; I was looking for a way to control the application volume. Greatly appreciated. Link to comment Share on other sites More sharing options...
birdofprey Posted April 22, 2007 Share Posted April 22, 2007 I looked into this a bit further than i had before. I looked to see if there was a way to even close or delete the object but all i found was that the Object variable assigned by the ObjCreate() function is just a pointer to an object not the object itself. And i also found this in the Autoit help file about objectsSo my guess is that setting $pObj = 0 is the way to go. I also having seen this and trying to test it futher, tried running this on my own and I saw no recurring increase in memory usage from my system. I have no clue what could have caused this for you, but I'm pretty sure it wasn't my UDF.Well, what can I say ? It beats me. Create an object. Load a song. Play the song. Close the object. Repeat. Then put your computer into hibernation. You'll see that even though you thought you closed the objects, before your system will hibernate, you'll get a number of messages, telling you something about your windows media object(s).About the memory increase. Compile your script. And monitor the private bytes allocated to the application in realtime. Still, I'll have a carefull second look at my script, but the amount of increase, 1-3 MB for every new song tells me ( I might be wrong ) that this is not something caused by one or two variables declared globally instead of locally or something like that.Cheers Link to comment Share on other sites More sharing options...
CFire Posted April 24, 2007 Author Share Posted April 24, 2007 (edited) About the memory increase. Compile your script. And monitor the private bytes allocated to the application in realtime. Still, I'll have a carefull second look at my script, but the amount of increase, 1-3 MB for every new song tells me ( I might be wrong ) that this is not something caused by one or two variables declared globally instead of locally or something like that.How do you monitor the private bytes of a program?? Is it the Mem Usage in the Task Manager under the processes tab?Also, when you play a new song, are you setting the $pObj = 0 Then setting it to $pObj = ObjCreate("WMPlayer.ocx")? This is something you dont need to do. You actually never have to set any of the objects used in this udf to zero, especially the $pObj. I did some tests and found that if you set the $pObj = 0 and reset it to $pObj = ObjCreate("WMPlayer.ocx") at every song change, the Mem Usage keeps goin up and up by about 600 KB for every song. If you dont do this and just keep the link to WMPlayer.ocx open and just change the song being played, then the Mem Usage Levels off after about 3 songs. I'm going to update my Functions and Example to use a WMStartPlayer() and WMClosePlayer() Functions and make it so you won't have to even deal with the Player Object, $pObj. All you will have to deal with is the Song Object, $sObj, which would be like the Track ID in Sound.au3. Edited April 24, 2007 by CFire [u]Scripts and UDF's[/u]WMMedia - UDF full of functions to Control Media Output. Link to comment Share on other sites More sharing options...
ConsultingJoe Posted April 24, 2007 Share Posted April 24, 2007 nice udf, thanks Check out ConsultingJoe.com Link to comment Share on other sites More sharing options...
CFire Posted April 24, 2007 Author Share Posted April 24, 2007 I Updated the File. See Top for Changes. I hope this will fix the Memory issues. [u]Scripts and UDF's[/u]WMMedia - UDF full of functions to Control Media Output. Link to comment Share on other sites More sharing options...
birdofprey Posted April 24, 2007 Share Posted April 24, 2007 I Updated the File. See Top for Changes. I hope this will fix the Memory issues.Good idea. This will most probably stop people from doing what I did in the beginning (reseting the player object). Doing so, made my app take over more than 80 MB of memory at some point, and it didn't seem to plan to stop there, which is exactly the opposite of what I was trying to achieve by reseting that. So, I changed my script to do things "the right way", and I did that before posting... but, what I got was increasing memory, again... I now only create a... $pObj once and reuse the object but, the private bytes allocated for the application are still increasing on every "songload"....and I got fed up a bit. Maybe that's why I didn't notice that this time it wouldn't go beyond 11.9 MB anymore. It gets stuck around 11.5 MB. Thanks for mentioning that things leveled off in your experiments. How do you monitor the private bytes of a program?? Is it the Mem Usage in the Task Manager under the processes tab?I use Sysinternal's Process Explorer, it's free and you can monitor more than memory, graphically with it. Right click your process, properties, performance graph tab. You might notice that those 600 KB are not necessarily 600 KB, cause what I get is very random. One more thing. What about media with variable bitrate ? Should I just poll WMGetBitrate($sObj) every now and then ? And how about a WMSetTitle(), WMSetAlbum(), WMSetGenre and so on ? Oh, and one more thing, Thanks ! Link to comment Share on other sites More sharing options...
Kip Posted May 2, 2007 Share Posted May 2, 2007 (edited) What do you think about Balance?! Func WMSetBalance($Balance) If $pObj <> 0 Then $pObj.settings.Balance = $Balance If $pObj = 0 Then SetError(1) EndFunc If you gonna put it in your script... Do you wanna put this in it to?: ; ==================================================================================================== ; Description ..: Sets the Balance of the Player. ; Parameters ...: $Balance - New Balance (Total Left: -100 to 100: Total Right) ; Return values : ; Author .......: Kip ; Notes ........: Does Not Affect System/Wave Volumes!! ; Sets @error = 1 When This Function has Been called Before WMStartPlayer() ; ==================================================================================================== I will try to get more functions. Kip Edited May 2, 2007 by kip MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API. Link to comment Share on other sites More sharing options...
birdofprey Posted May 2, 2007 Share Posted May 2, 2007 I can only thank you for it ! Where do you find these ? Link to comment Share on other sites More sharing options...
Kip Posted May 2, 2007 Share Posted May 2, 2007 (edited) I was just trying some things for my own audio mixing program, and...: Tadaa! (and with a little help of google ) Edited May 2, 2007 by kip MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now